You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
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.
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.
@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.
Activity
bugok commentedon Jul 9, 2015
@tstarling: thanks for reporting this.
I'm looking into it.
bugok commentedon Jul 14, 2015
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
bugok commentedon Jul 15, 2015
I'll try to get a repro using a Transaction/Session.
tstarling commentedon Jul 15, 2015
If you want to follow the way I discovered this:
The zero at the end should not be there. I confirmed its origin as described above using gdb.
bugok commentedon Jul 23, 2015
@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.
tstarling commentedon Jul 28, 2015
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.
bugok commentedon Jul 30, 2015
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.
tstarling commentedon Jul 30, 2015
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.
afrind commentedon Jul 31, 2015
@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.
tstarling commentedon Jul 31, 2015
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."
afrind commentedon Jul 31, 2015
@tstarling : oops, was just looking at the diff which didn't have the detail. Will get you unblocked ASAP.
Fix body sent on HEAD request
afrind commentedon Aug 18, 2015
Fix has been pushed
Fix shebang in shell_builder (#51)
eden/edenapi and mononoke integration tests: add edenapi/tools to get…