http: add 'sendingHeaders' event for response header manipulation#63996
http: add 'sendingHeaders' event for response header manipulation#63996bjohansebas wants to merge 2 commits into
Conversation
|
Review requested:
|
4d08718 to
0e6deb8
Compare
0e6deb8 to
4f83f42
Compare
bjohansebas
left a comment
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?
Ethan-Arrowood
left a comment
There was a problem hiding this comment.
Nice work. I'm +1 on landing something like this to eliminate the monkey-patching in on-headers package.
I think this should be semver-minor btw.
4f83f42 to
8cab90a
Compare
Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
8cab90a to
7b8a916
Compare
|
Okay, I added the safeguard you mentioned—good catch. Also, |
There was a problem hiding this comment.
This is to prevent regressions while making the changes
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #63996 +/- ##
==========================================
+ Coverage 90.23% 90.25% +0.01%
==========================================
Files 741 741
Lines 241692 241742 +50
Branches 45541 45558 +17
==========================================
+ Hits 218097 218178 +81
+ Misses 15113 15103 -10
+ Partials 8482 8461 -21
🚀 New features to boost your workflow:
|
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