-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Always skip body for 1xx, 204, and 304 responses #464
base: main
Are you sure you want to change the base?
Always skip body for 1xx, 204, and 304 responses #464
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the change LGTM in general I'm kind of worried it might break existing http-parser consumers due to the change in behavior.
@@ -1848,8 +1848,7 @@ const struct message responses[] = | |||
,.http_minor= 1 | |||
,.status_code= 101 | |||
,.response_status= "Switching Protocols" | |||
,.body= "body" | |||
,.upgrade= "proto" | |||
,.upgrade= "bodyproto" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #363, it's possible someone might be relying on the current behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR only changes the tests for 101 responses. The HTTP_200_RESPONSE_WITH_UPGRADE_HEADER* tests are unaffected (and they all pass).
RFC 7230 explicitly forbids using Content-Length or Transfer-Encoding in 1xx responses ("A server MUST NOT send" etc.) and RFC 2616 also had similarly strict requirements ("All 1xx ... responses MUST NOT include a message-body"), so I think it would probably be ok.
It's quite hard to tell if this behavior change will affect anyone since it seems that these responses are rarely encountered in the wild if at all: 1xx, 204, and 304 responses without a declared message body length are already correctly handled by the parser, while 1xx and 204 with a message body are not legitimate according to the spec, and real servers often do not include content-length or transfer-encoidng in 304 responses (at least IIS, nginx and apache httpd don't). So there's a great chance that this change is harmless but also purely cosmetic and no-one actually needs it. |
cc @indutny - perhaps you can weigh in? |
I think it might be too hard to propagate description this change to the consumers of http-parser. In order to properly do it, we'll have to do major release. @nodejs/http : do we consider major release a possibility, or would we prefer to stick with llhttp and do majority of changes there instead? |
c253f0b
to
c70bd21
Compare
Just for the record: I will try to keep this branch rebased on top of the current master in case anyone wants to use it before the next major release. |
"status_code >= 100 && status_code < 200" might be faster than "status_code / 100 == 1"
c70bd21
to
b25158b
Compare
https://tools.ietf.org/html/rfc7230#section-3.3.3:
... any response with a 1xx (Informational), 204 (No Content), or 304 (Not Modified) status code is always terminated by the first empty line after the header fields, regardless of the header fields present in the message, and thus cannot contain a message body.
Fixes: #251