New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: close the connection after sending a body without declared length #46333
base: main
Are you sure you want to change the base?
Conversation
Previously, if you removed both content-length and transfer-encoding headers, the connection would still be kept-alive by default. This isn't helpful, because without those headers, the only way the client knows when the body is completed is when the connection closes. See https://www.rfc-editor.org/rfc/rfc7230#section-3.3.3 for more details on this message body handling logic (this is case 7). This meant that in effect, if you removed both headers every response came with a 5 second delay at the end (the default KA timeout) before the client could process it. Now, if you remove both headers the connection closes automatically immediately, so the client knows that it has received the whole message body.
|
Review requested:
|
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.
lgtm
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.
LGTM.
Unfortunately, this is a semver-major change so only Node 20 and beyond will benefit from this.
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.
lgtm


This is related to #46331 but not directly dependent - it's a separate issue I've just noticed en route.
Previously, if you removed both the content-length and transfer-encoding headers, everything was sent as normal, and the connection would still be kept alive by default. This is problematic, because without those headers to declare the size of the message body, the only way the client knows when the body is completed is when the connection closes. With KA, the connection doesn't close for ages.
See https://www.rfc-editor.org/rfc/rfc7230#section-3.3.3 for more details on this message body handling logic. This is the final case (7):
This meant that in effect, if you removed both headers then every response came with a 5 second delay at the end (the default KA timeout) before the client could process it.
With this PR, if you remove both headers then the connection closes automatically immediately, so the client knows straight away that it has received the whole message body and everything works correctly.
This does behave slightly differently with & without #46331:
Note that the only test covering this does exactly that, so the modified test here actually still passes on
maineven without this change.