Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Need to consider the noBody situation for HEAD method #401

Open
tianchao-haohan opened this issue Dec 18, 2017 · 3 comments
Open

Need to consider the noBody situation for HEAD method #401

tianchao-haohan opened this issue Dec 18, 2017 · 3 comments

Comments

@tianchao-haohan
Copy link

tianchao-haohan commented Dec 18, 2017

Here is the diff code:

+++ b/src/3rd_party/http_parser/http_parser.c
@@ -1783,8 +1783,9 @@ reexecute:

         hasBody = parser->flags & F_CHUNKED ||
           (parser->content_length > 0 && parser->content_length != ULLONG_MAX);
-        if (parser->upgrade && (parser->method == HTTP_CONNECT ||
-                                (parser->flags & F_SKIPBODY) || !hasBody)) {
+        if ((parser->upgrade && (parser->method == HTTP_CONNECT ||
+                                (parser->flags & F_SKIPBODY) || !hasBody))
+                                || parser->method == HTTP_HEAD) {
           /* Exit, the rest of the message is in a different protocol. */
           UPDATE_STATE(NEW_MESSAGE());
           CALLBACK_NOTIFY(message_complete);
@bnoordhuis
Copy link
Member

Can you go in more detail? The diff doesn't look Obviously Correct to me.

@tianchao-haohan
Copy link
Author

tianchao-haohan commented Aug 14, 2018

@bnoordhuis There is no http request body for the http request with HEAD method. And I found that the parser can't be finished normally (on_message_complete callbacks is triggered) in this situation.

@ploxiln
Copy link
Contributor

ploxiln commented Aug 14, 2018

This change matches a HEAD request (which had Upgrade headers or for which the user returned 2 from the on_headers_complete callback). A HEAD response may have a Content-Length but does not include the body. A HEAD request does not have the same rule. It really should not have a body, but if it has a non-zero Content-Length, the body must be present (and should be ignored by the server).

https://tools.ietf.org/html/rfc7231#section-4.3.2

A payload within a HEAD request message has no defined semantics;
sending a payload body on a HEAD request might cause some existing
implementations to reject the request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants