Repository navigation
http: add 'sendingHeaders' event for response header manipulation - #63996
bjohansebas wants to merge 4 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.
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.48% 90.49%
=======================================
Files 797 797
Lines 277491 277560 +69
Branches 53318 53345 +27
=======================================
+ Hits 251091 251167 +76
- Misses 16793 16806 +13
+ Partials 9607 9587 -20
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com> Assisted-by: Codex
6833386 to
e6f74b6
Compare
Co-authored-by: Ethan Arrowood <ethan@arrowood.dev> Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
Preserve differently cased inline header fields when a sendingHeaders listener requires them to be cached, retaining existing stored-header overwrite behavior. Copy array values before combining duplicate fields so reused headers do not accumulate cookies across responses and frozen arrays remain valid. Add regression coverage for duplicate cookies and reused header arrays with and without listeners, stored headers, and frozen values. Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
Honor an empty statusMessage explicitly assigned by a sendingHeaders listener instead of replacing it with the default reason phrase. Keep legacy defaults for implicit empty reasons while preserving an empty reason chosen by the listener, including during reentrant writeHead(). Add regression coverage for explicit and implicit header flushing, once listeners, and unchanged falsy status messages. Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
e6f74b6 to
fec7059
Compare
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