-
-
Notifications
You must be signed in to change notification settings - Fork 33k
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
base: main
Are you sure you want to change the base?
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 89.95% 88.26% -1.69%
==========================================
Files 667 702 +35
Lines 196776 206717 +9941
Branches 38409 39764 +1355
==========================================
+ Hits 177006 182461 +5455
- Misses 12198 16271 +4073
- Partials 7572 7985 +413
🚀 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 ( |
Signed-off-by: RafaelGSS <[email protected]> Co-Authored-By: RafaelGSS <[email protected]>
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.
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.
Unfortunately this new option is not easy to turn on by default because it's blocking a valid case, the HTTP/1.0 case where a request is made and the socket half closed to signal its termination. I would rather have it enabled based on the HTTP method instead.
Backportable version of #59747
cc: @ronag