-
-
Couldn't load subscription status.
- Fork 33.6k
http: add optimizeEmptyRequests option for IncomingMessage._dump #59778
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
Conversation
|
Review requested:
|
7961667 to
6e5fdcb
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #59778 +/- ##
=======================================
Coverage 88.45% 88.45%
=======================================
Files 703 703
Lines 207546 207579 +33
Branches 40011 40011
=======================================
+ Hits 183591 183622 +31
- Misses 15949 15951 +2
Partials 8006 8006
🚀 New features to boost your workflow:
|
lib/_http_server.js
Outdated
| const fastDump = options.fastDump; | ||
| if (fastDump !== undefined) | ||
| validateBoolean(fastDump, 'options.fastDump'); | ||
| this[kfastDump] = fastDump || false; |
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.
The OR seems redudant since we are passing through validateBoolean
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.
How so? if fastDump is undefined, this[kfastDump] will be undefined instead of false.
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.
You could shortcut that just a bit by assigning a default:
const { fastDump = false } = options.fastDump;
validateBoolean(fastDump, 'options.fastDump');
this[kfastDump] = fastDump;|
Thinking more about the heuristics mentioned at the end #59747, it looks like we can go further and do even better here, very easily. I think we can do this for all methods, quickly & safely, because it's already impossible to receive a request with a body without it being indicated it in the headers (content-length or transfer-encoding), even in the current implementation, even for POST and others etc. On Node v24 right now, if you send: Then Node currently fires That means we could safely apply this optimization to all cases, whenever there's no This would still be breaking behaviour, because it doesn't emit end or close events, but as an opt-in option ( |
6e5fdcb to
2d617ab
Compare
|
Just pushed a new version (amended) that replaces the PTAL. |
lib/_http_server.js
Outdated
| // stream.Readable life cycle rules. The downside is that this will | ||
| // break some servers that read bodies for methods that don't have body headers. | ||
| req._dumped = true; | ||
| req._readableState.ended = true; |
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.
Could we move the modifications of stream internals into stream files?
I wonder also that endEmitted/ closeEmitted are set here. Are they really emitted?
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.
I wonder also that endEmitted/ closeEmitted are set here. Are they really emitted?
They are as if they were already emitted.
This comment was marked as outdated.
This comment was marked as outdated.
e33471d to
e6cd7d2
Compare
doc/api/http.md
Outdated
| or `Transfer-Encoding` headers (indicating no body) will be initialized with an | ||
| already-ended body stream, so they will never emit any stream events | ||
| (like `'data'` or `'end'`). You can use `req.readableEnded` to detect this case. | ||
| This option is still under experimental phase. |
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.
If this is indeed true, we should emit an experimental warning whenever this flag is used. If this is no longer correct, we should remove this comment.
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.
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.
Than I recommend emitting a warning if it's not inside node_modules?
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.
I have added the experimental documentation here only for the next two v24 releases at least, just in case we are missing some specific edge case that would completely change how this flag works - you know, touching on http usually breaks people in many ways. Ideally, this line should be removed in a couple of releases.
I'm not sure if it's worth it to consider such a warning since we'll remove it very soon.
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.
@anonrig I have removed the experimental comment.
e6cd7d2 to
29753ac
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Ping @anonrig |
Signed-off-by: RafaelGSS <[email protected]> Co-Authored-By: RafaelGSS <[email protected]>
29753ac to
3a95d3d
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Landed in 0c35aaf |
Signed-off-by: RafaelGSS <[email protected]> Co-Authored-By: RafaelGSS <[email protected]> PR-URL: #59778 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Tim Perry <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
Backportable version of #59747
cc: @ronag