Skip to content

Body still being sent for HEAD requests #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fasterthanlime opened this issue Jun 28, 2020 · 4 comments
Closed

Body still being sent for HEAD requests #623

fasterthanlime opened this issue Jun 28, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@fasterthanlime
Copy link
Contributor

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.

@jbr jbr added the bug Something isn't working label Jun 28, 2020
@Fishrock123
Copy link
Member

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

@yoshuawuyts
Copy link
Member

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

@jbr
Copy link
Member

jbr commented Jun 30, 2020

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

@yoshuawuyts
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants