creationix/http-parser-js

bodyless responses

Closed this issue · 2 comments

The http spec says about the HEAD request:

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request.

This module isn't able to parse such a method, because it reads the Content-Length header and then expects to read a body. Since there is none, kOnMessage is never called.

I think it should be possible to tell the parser that the EOF has been reached, and that it shouldn't expect any more input.

That is not true, the module is able to correctly parse HEAD responses. However it is not the responsibility of the http parser to determine wheter it is a HEAD response, because that information is only in the request, not in the response. Instead, this is done by the http module.
It works the same way in the original node http_parser.

I see, sorry for the false report. In my mind, HEAD requests were ended after the remote server had closed the connection with a FIN signal (and even if it worked like that, I noticed the .finish method right after posting, so I was wrong anyway).