Tide: Body still being sent for HEAD requests

Created on 28 Jun 2020  路  4Comments  路  Source: http-rs/tide

Bug Report

Current Behavior

Whenever a HEAD request is made, if it's routed to a GET handler, a tide server will reply with the correct headers but it'll also serve the full body.

Code/Gist

I don't have a small reproduction test case right now, but hopefully it should be pretty easy to verify that this happens. I'm curious why the test introduced in #179 doesn't catch it - maybe because it uses a test server, not the real thing?

Expected behavior/code

I would expect tide to serve the correct headers (including content-length), but not the body.

As things stand, I can't implement HEAD correctly, because either I let the GET handler do its thing, and tide sends the whole body, or I add a wrapper that runs the GET handler and overrides the body to be empty - but insert_header("content-length") is always overwritten later by tide itself, so that would be an invalid HEAD response.

Environment

  • tide version: 0.11.0
  • Rust toolchain version(s): 1.44.1
  • OS: Linux, Windows 10, any tbh

Possible Solution

I haven't looked too closely at the how responses are actually handled by tide, so I'm not sure.

Additional context/Screenshots

This is how curl behaves:

$ curl -X HEAD http://localhost:1111/ 2>&1 | head -20
Warning: Setting custom HTTP method to HEAD with -X/--request may not work the 
Warning: way you want. Consider using -I/--head instead.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0<!DOCTYPE html>
<html lang="en">

<head>
    <title>

        fasterthanli.me

    </title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<meta name="robots" content="noodp"/>

<link rel="stylesheet" href="/style.01ebxdp48thp88vghj60msqtx4.css">
<link rel="shortcut icon" href="/img/logo-round.png">

For comparison, curl -X HEAD -v http://example.org shows the headers, then hangs - because curl expects the body to be there.

Note that curl's --head or -I options hide the problem. They never read the body, whether the server sends it or not.

bug

Most helpful comment

@yoshuawuyts See http-rs/async-h1#124 for a fix

All 4 comments

I too noticed this in tests for tide-compress but I forgot to file it here.

@fasterthanlime thanks for reporting! I suspect this is an issue in async-h1 and I've opened an issue there: https://github.com/http-rs/async-h1/issues/125

@yoshuawuyts See http-rs/async-h1#124 for a fix

Just published [email protected] which fixes this issue! :tada: @fasterthanlime thanks for reporting and @jbr thanks for fixing!

Was this page helpful?
0 / 5 - 0 ratings