http: add 'sendingHeaders' event for response header manipulation#63996
Open
bjohansebas wants to merge 2 commits into
Open
http: add 'sendingHeaders' event for response header manipulation#63996bjohansebas wants to merge 2 commits into
bjohansebas wants to merge 2 commits into
Conversation
Collaborator
|
Review requested:
|
metcoder95
reviewed
Jun 19, 2026
4d08718 to
0e6deb8
Compare
Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
0e6deb8 to
4f83f42
Compare
bjohansebas
commented
Jun 25, 2026
bjohansebas
left a comment
Member
Author
There was a problem hiding this comment.
Okay, continuing with this, Express would have an interesting situation here. While on-headers would run first and then this new event would run afterward, it could cause issues with things like compression, since it might overwrite work that was already done internally by on-headers, potentially breaking applications.
In other words, this would affect compression and other middleware. From the Express side that might not be a huge problem, but I'm not sure about the rest of the ecosystem. That's why I'm not sure whether this should be considered a semver-major change @nodejs/http @nodejs/tsc?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Okay, after so much time I can finally find time for this. Meanwhile, I’m still testing locally because building Node is quite heavy.
In summary, this serves as a replacement for on-headers, which is a package that does monkey-patching. The idea is to have an event so that middlewares like compression or express-session can use it to modify headers, and for now also, in the case of compression, to transform it into a gzip stream and send the data. However, we will still need two more events to fully remove the monkey-patching of res.write and res.end used in compression, express-session, and many other middlewares
cc: @blakeembrey