Fix HTTP 1.1 read until EOF / connection close behavior#79
Conversation
Unless this is a response to a HEAD request, http-parser cannot determine the length of the body. So, it should read until EOF. (It does not match .1-4 of sec 4.4, then .5 is applied.)
You should respond with |
|
Thanks, but like @koichik said, it's not possible to determine the response body's size so there is no alternative but to read until EOF. The 'single-line response to a HEAD request' case doesn't set the keep-alive flag right now because the parser doesn't know that it's a response to a HEAD request. I suppose that could be fixed (probably not easily) and it should be sufficiently uncommon that it's a minor optimization at best. |
|
@bnoordhuis - If |
|
I'm not talking about HEAD requests. http://tools.ietf.org/html/rfc2616#section-4.4 5. If you think about it's pretty consistent because the client shouldn't close the connection (and the server don't expect the client to) if there is no connection: close header. |
|
What I suggested was in complement to that, but reading other parts of the RFC, I realize it doesn't matter. The scenario I was describing shouldn't happen if the server follows the RFC. I just need to change my test cases. Sorry to have bothered you about it and thank you for this great parser. |
The parser should not close the connection nor try to read until EOF if the protocol is 1.1 and the Connection: close header is not set according to the RFC[1]. This was making the parser to close the connection for every message without a body if the Content-Length was not 0.
For example:
Should not close the connection.
Should read until EOF and close the connection.
[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4 (.5)