Skip to content

http: add 'sendingHeaders' event for response header manipulation#63996

Open
bjohansebas wants to merge 2 commits into
nodejs:mainfrom
bjohansebas:on-header-solution
Open

http: add 'sendingHeaders' event for response header manipulation#63996
bjohansebas wants to merge 2 commits into
nodejs:mainfrom
bjohansebas:on-header-solution

Conversation

@bjohansebas

@bjohansebas bjohansebas commented Jun 19, 2026

Copy link
Copy Markdown
Member

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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Jun 19, 2026
Comment thread doc/api/http.md
@bjohansebas bjohansebas requested a review from mcollina June 19, 2026 15:37

@bjohansebas bjohansebas left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

http Issues or PRs related to the http subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants