GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http,http2: copy header arrays in setHeader by Ethan-Arrowood · Pull Request #67528 · nodejs/node

Conversation

@Ethan-Arrowood

@Ethan-Arrowood Ethan-Arrowood commented Nov 16, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

setHeader() stores an array value by reference. appendHeader() then pushes new values into that same array mutating the stored reference. A frozen array makes appendHeader() throw a TypeError.

This makes setHeader() store a copy of an array value, so the response owns its header arrays. appendHeader() keeps pushing in place, which is now safe. The HTTP/2 compat API is also updated.

getHeader() and getHeaders() still return the stored array. Mutating that array still changes the response, as the getHeaders() docs describe.

Fixes: #67526

Semver

I'm unsure if this should be a patch fix or a major breaking change. Technically we never documented that the response shares the array reference. So we could just consider it a fix. However, if anyone was relying on this behavior it could break them which is why I'm personally leaning towards marking this as a semver major change.

If we go with major and want a fix for older release lines, a smaller patch could copy inside appendHeader() instead. That fixes the mutation and the frozen-array throw without changing setHeader(). The cost is a copy on every append, so repeated appends to one header will be a performance hit.

Tests

  • New test/parallel/test-http-outgoing-append-header-array.js covers setHeader(), appendHeader(), setHeaders(), and writeHead() with plain and frozen arrays.
  • test/parallel/test-http2-compat-serverresponse-headers.js gets the same check for HTTP/2.
  • I changed an existing test, test/parallel/test-http2-compat-get-headers.js. It asserted that getHeaders()['set-cookie'] is the exact array passed to setHeader(). It now compares against the stored array instead. It still checks that getHeaders() is a shallow copy whose array values are the response's own.

Notes

  • This uses value.slice() rather than ArrayPrototypeSlice(). The lint rule that forbids prototype primordials in the HTTP and HTTP/2 files still lists the old lib/_http_*.js paths, so it doesn't cover lib/internal/http/. I'm opening a separate PR to update it: tools: apply http lint rule to lib/internal/http #67529
  • http: add 'sendingHeaders' event for response header manipulation #63996 copies each array before calling appendHeader() in writeHead(). With this change, those copies wouldn't be needed.

AI-assisted (Claude Opus 5.5, my setup). The words are my own, per the Human Voice policy.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Ethan-Arrowood
http,http2: copy header arrays in setHeader
26f810e
setHeader() stored the caller's array and that led to mutation
issues with appendHeader() pushing new values into it. The caller
would see values added to that array, and if the array was frozen
appendHeader() would throw a TypeError.

This fix copies the array value instead so the response instance
owns it completely. getHeader() still return the stored array.

It also applies the same change to HTTP2 compat api.

Fixes: nodejs#67526
Assisted-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ethan Arrowood <[email protected]>
@nodejs-github-bot

nodejs-github-bot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/http2
  • @nodejs/net
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added http Issues and PRs related to the http subsystem. http2 Issues and PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. labels Nov 16, 2026
bjohansebas
bjohansebas approved these changes Nov 16, 2026
View reviewed changes
@codecov

codecov Bot commented Nov 16, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.66%. Comparing base (428dd86) to head (26f810e).
⚠️ Report is 91 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67528      +/-   ##
==========================================
- Coverage   90.67%   90.66%   -0.01%     
==========================================
  Files         799      799              
  Lines      280314   280321       +7     
  Branches    54128    54127       -1     
==========================================
- Hits       254171   254159      -12     
- Misses      16273    16285      +12     
- Partials     9870     9877       +7     
Files with missing lines Coverage Δ
lib/internal/http/outgoing.js 98.00% <100.00%> (+<0.01%) ⬆️
lib/internal/http2/compat.js 97.27% <100.00%> (+<0.01%) ⬆️

... and 28 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Nov 19, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added the baking-for-lts PRs whose changes need more time before an LTS backport. label Nov 19, 2026
@mcollina

mcollina commented Nov 19, 2026

Copy link
Copy Markdown
Member

I would lean towards a bug fix

Ethan-Arrowood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pimterry
pimterry approved these changes Nov 19, 2026
View reviewed changes

@pimterry pimterry left a comment

Copy link
Copy Markdown
Member

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, happy to treat this as a bug fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Ethan-Arrowood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@pimterry pimterry added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 19, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/79301/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gurgunday
gurgunday approved these changes Nov 19, 2026
View reviewed changes
@Ethan-Arrowood Ethan-Arrowood added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 86b9e35 into nodejs:main Nov 19, 2026
83 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Landed in 86b9e35

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
@Ethan-Arrowood Ethan-Arrowood mentioned this pull request Nov 19, 2026
http: cache header validation in setHeader() #67232
Open
aduh95 pushed a commit that referenced this pull request Nov 20, 2026
@Ethan-Arrowood @aduh95
http,http2: copy header arrays in setHeader
1be7d94
setHeader() stored the caller's array and that led to mutation
issues with appendHeader() pushing new values into it. The caller
would see values added to that array, and if the array was frozen
appendHeader() would throw a TypeError.

This fix copies the array value instead so the response instance
owns it completely. getHeader() still return the stored array.

It also applies the same change to HTTP2 compat api.

Fixes: #67526
Assisted-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ethan Arrowood <[email protected]>
PR-URL: #67528
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Tim Perry <[email protected]>
Reviewed-By: Gürgün Dayıoğlu <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2026-11-25, Version 27.0.0-alpha.0.2.0 (Alpha) #67757
Merged
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@Ethan-Arrowood @gabylb
http,http2: copy header arrays in setHeader
a4cc75e
setHeader() stored the caller's array and that led to mutation
issues with appendHeader() pushing new values into it. The caller
would see values added to that array, and if the array was frozen
appendHeader() would throw a TypeError.

This fix copies the array value instead so the response instance
owns it completely. getHeader() still return the stored array.

It also applies the same change to HTTP2 compat api.

Fixes: nodejs#67526
Assisted-by: Claude Opus 5.5 <[email protected]>
Signed-off-by: Ethan Arrowood <[email protected]>
PR-URL: nodejs#67528
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Tim Perry <[email protected]>
Reviewed-By: Gürgün Dayıoğlu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@pimterry pimterry pimterry approved these changes
@gurgunday gurgunday gurgunday approved these changes
+1 more reviewer
@bjohansebas bjohansebas bjohansebas approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

baking-for-lts PRs whose changes need more time before an LTS backport. http Issues and PRs related to the http subsystem. http2 Issues and PRs related to the http2 subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

http: appendHeader() mutates the array passed to setHeader()

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@Ethan-Arrowood @nodejs-github-bot @mcollina @pimterry @gurgunday @bjohansebas
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.