Skip to content

http2: add headersDistinct to Http2ServerRequest fixes #64060#64071

Open
Shivay-98 wants to merge 1 commit into
nodejs:mainfrom
Shivay-98:main
Open

http2: add headersDistinct to Http2ServerRequest fixes #64060#64071
Shivay-98 wants to merge 1 commit into
nodejs:mainfrom
Shivay-98:main

Conversation

@Shivay-98

Copy link
Copy Markdown

Adds headersDistinct to Http2ServerRequest to improve parity with
http.IncomingMessage.

The implementation mirrors IncomingMessage.headersDistinct by
lazily constructing a null-prototype object from rawHeaders and
preserving all header values as arrays.

Includes tests covering:

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http2
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added http2 Issues or PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. labels Jun 22, 2026

@pimterry pimterry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work, thanks @Shivay-98!

There's a few JS linting issues to fix here (you can check locally with make lint). For the commit linting issue, you'll need to run git commit --amend -s to update the commit with the signed-off signature, and then force-push to update the commit here.

It'd be good to also include this change in the docs, in the compat API section in http2.md.

Comment thread lib/internal/http2/compat.js Outdated
const kSetHeader = Symbol('setHeader');
const kAppendHeader = Symbol('appendHeader');
const kAborted = Symbol('aborted');
const kHeadersDistinct = Symbol('kHeadersDistinct');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: for symbols, generally the name doesn't have the k prefix - it's just the meaningful string

@Ethan-Arrowood Ethan-Arrowood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree with @pimterry 's review. Once you fix lint and address the nits this is good to go.

Comment thread lib/internal/http2/compat.js Outdated
const raw = this[kRawHeaders];

for (let i = 0; i < raw.length; i += 2) {
const name = String(raw[i]).toLowerCase();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The String() might not be necessary.

Signed-off-by: Shivay-98 <shivay8306@gmail.com>
@Shivay-98

Copy link
Copy Markdown
Author

Thanks @pimterry @Ethan-Arrowood for the review! I've addressed the requested changes:

  • Fixed the lint/style nits in compat.js.
  • Changed the symbol description to Symbol('headersDistinct').
  • Removed the unnecessary String() call.
  • Added documentation for request.headersDistinct in doc/api/http2.md.
  • Amended the commit with a DCO sign-off.

I'd appreciate it if you could take another look when you have a chance. Thanks again!

@pimterry pimterry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's just a couple more changes to do on the docs here. There's also still a linting failure on the code.

You can run make lint to run all the linting checks locally before pushing, which will make these easier to catch. You might also want to run make docserve which will build & serve the docs locally, so you can check the output.

Comment thread doc/api/http2.md
@@ -4187,6 +4189,53 @@ removeAllHeaders(request.headers);
assert(request.url); // Fails because the :path header has been removed
```

#### `request.headersDistinct`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The docs here are duplicated. One of these needs removing.

Comment thread doc/api/http2.md

* Type: {Object}

Similar to [`request.headers`][], but there is no join logic and the values are

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This link name is defined in http.md but not here in http2.md.

If you want to keep it in the de-dupe, we'll need another definition here to make the link work. You can see those at the bottom of the file, just add this in there alphabetically.

Comment thread doc/api/http2.md
<!-- YAML
added:
- v18.3.0
- v16.17.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In whichever doc you keep, the version number here should be left as a placeholder. It'll be automatically filled out when this is released, like so:

added:
  - version: REPLACEME

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.22%. Comparing base (e6a8d06) to head (cabf67a).
⚠️ Report is 344 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/http2/compat.js 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64071      +/-   ##
==========================================
- Coverage   92.01%   90.22%   -1.80%     
==========================================
  Files         379      741     +362     
  Lines      166972   241713   +74741     
  Branches    25554    45543   +19989     
==========================================
+ Hits       153639   218081   +64442     
- Misses      13041    15163    +2122     
- Partials      292     8469    +8177     
Files with missing lines Coverage Δ
lib/internal/http2/compat.js 97.00% <92.00%> (-0.22%) ⬇️

... and 550 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.

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

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

headersDistinct for http2 requests

4 participants