Skip to content

Body sent on HEAD request #51

Closed
Closed

Description

@tstarling

As noted at https://reviews.facebook.net/D38373 , Proxygen does not suppress the sending of the response body when the request is a HEAD request. In fact, even if the application sends no response data, if the HTTPMessage::chunked_ flag is set, HTTP1xCodec::generateEOM() will send an empty chunk "0\r\n", which is a protocol violation.

It's arguable whether a Transfer-Encoding header should be sent on HEAD, but either way, the policy should be Proxygen's responsibility, rather than the application's, which means that the application should be allowed to call HTTPMessage::setIsChunked() on the response to a HEAD request without causing a protocol violation.

I'm not sure how much help Proxygen should give to applications wishing to implement HEAD handling. Certainly, it should not require applications to send a response body to Proxygen to be discarded, since that is inefficient, but maybe Proxygen could automatically discard a response body if one is given.

Activity

  1. bugok commented on Jul 9, 2015

    @bugok
    Contributor

    @tstarling: thanks for reporting this.
    I'm looking into it.

  2. bugok commented on Jul 14, 2015

    @bugok
    Contributor

    I'm having trouble to reproduce this. I tested the following test case to proxygen/lib/http/codec/test/HTTP1xCodecTest.cpp and it works.

    Could you please help with a simple repro?

    https://gist.github.com/bugok/f631e8aa448b00889bf6

  3. bugok commented on Jul 15, 2015

    @bugok
    Contributor

    I'll try to get a repro using a Transaction/Session.

  4. tstarling commented on Jul 15, 2015

    @tstarling
    Author

    If you want to follow the way I discovered this:

    diff --git a/hphp/runtime/server/proxygen/proxygen-transport.cpp b/hphp/runtime/server/proxygen/proxygen-transport.cpp
    index 6cd78ce..1cc7045 100644
    --- a/hphp/runtime/server/proxygen/proxygen-transport.cpp
    +++ b/hphp/runtime/server/proxygen/proxygen-transport.cpp
    @@ -564,7 +564,7 @@ void ProxygenTransport::sendImpl(const void *data, int size, int code,
         // If it is a HEAD request, lie to Proxygen about the chunked status, since
         // Proxygen is broken and will send a response body consisting of an empty
         // chunk if the chunked flag is set.
    -    m_response.setIsChunked(chunked && !suppressBody);
    +    m_response.setIsChunked(chunked /* && !suppressBody*/);
    
         m_response.dumpMessage(4);
         m_server->putResponseMessage(
    
    • Compile
    • Make a PHP script that sends chunked output, e.g.
    <?php
    echo "Line 1\n";
    flush();
    echo "Line 2\n";
    
    • Configure with proxygen server enabled
    • Do a HEAD request for the test script, using a raw client like netcat:
    echo "HEAD /dcc.php HTTP/1.1
    Host: localhost
    " | nc -C localhost 9000
    
    HTTP/1.1 200 OK
    Vary: Accept-Encoding
    Content-Type: text/html
    X-Powered-By: HHVM/3.8.0-dev
    Transfer-Encoding: chunked
    Date: Wed, 15 Jul 2015 00:34:46 GMT
    Connection: keep-alive
    
    0
    

    The zero at the end should not be there. I confirmed its origin as described above using gdb.

  5. bugok commented on Jul 23, 2015

    @bugok
    Contributor

    @tstarling: I think I might have something, but I'm not completely sure if this is the right fix. I'm having trouble with creating a decent test case for this. However, it doesn't break any of the other proxygen unit tests.
    Could you please patch with this and let us know if it helps?
    https://gist.github.com/bugok/5e0dbca599509d5436c7

    Thanks.

  6. tstarling commented on Jul 28, 2015

    @tstarling
    Author

    That still sends an extra CRLF in the HEAD response. You could do something like https://gist.github.com/tstarling/f28f1da1eedd8a31b3bf . That fixes my test case, at least.

  7. bugok commented on Jul 30, 2015

    @bugok
    Contributor

    Thanks for doing this @tstarling!
    Due to legal issues - could you please send this as a pull request? I'd need you to sign the CLA in order to use that. I'll check the validity of the fix and add a test case.

  8. tstarling commented on Jul 30, 2015

    @tstarling
    Author

    The reason this is a bug report rather than a pull request is because proxygen is not fully open source, so I don't want to write code for it. I would have preferred to not even write the bug report, except that afrind is blocking about a month's worth of work against HHVM on the basis that a one-line workaround for this bug is not acceptable. All I did in that patch is move the if block out by a couple of lines, and I don't think I deserve to be identified as the author of such a trivial change, although of course I have signed the Facebook CLA. Submitting code as a PR rather than a bug comment would shift responsibility -- next you'll be asking me to move a space or a comma, or fix some private unit test failure.

  9. afrind commented on Jul 31, 2015

    @afrind
    Contributor

    @tstarling : the HHVM PR is closed as far as I can tell. Always feel free to ping directly in a diff if I am holding something up. As for the part of proxygen that is not open source, I don't think you should treat this differently than any other application that is built by a third-party on top of libproxygen. As long as the library change is correct, has test coverage, and passes other OSS unit tests, we will accept the PR and handle any fallout on our side.

    That said if you'd rather not submit this as a PR will can fix it on our side. Thanks again for finding the issue and contributing.

  10. tstarling commented on Jul 31, 2015

    @tstarling
    Author

    The HHVM PR was closed unmerged, Fred closed it with the comment "Getting this out of the HHVM queue for now, pending fixes in proxygen."

  11. afrind commented on Jul 31, 2015

    @afrind
    Contributor

    @tstarling : oops, was just looking at the diff which didn't have the detail. Will get you unblocked ASAP.

  12. added a commit that references this issue on Aug 11, 2015
  13. afrind commented on Aug 18, 2015

    @afrind
    Contributor

    Fix has been pushed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions