Ensure conflicting flat headers in HTTP/2 are combined correctly #4196
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.
This relates to...
When passing a flat header array and using HTTP/2, duplicate keys were discarded and lost unexpectedly.
In addition, the value-combining formatting (effectively
join(',')
) for explicitly array-valued headers in HTTP/2 didn't quite match the formatting for both Undici HTTP/1 or for Node HTTP/2's value-combining behaviour for headers that differ only by case (both of which dojoin(', ')
- i.e. with whitespace) which was a bit weird.Rationale
The response shows what the server receives: headers including
a: c
but withouta: b
(all but the last header value is lost).The header array-to-object logic ignored duplicate keys like this.
Regarding the formatting:
{ 'a': ['b', 'c'] }
is sent asa: b, c
(whitespace){ 'a': 'b', 'A': 'c' }
is sent asa: b, c
(whitespace){ 'a': ['b', 'c'] }
was sent asa: b,c
(no whitespace)(I'm not claiming this formatting is particularly important, but I would've had to reproduce the inconsistency in the tests, and it's nicer to tidy it up & make these headers a bit more readable en route).
Once nodejs/node#57917 is released (e.g. Node v24) we will be able to skip this entirely, and pass raw headers as-is directly to Node's HTTP/2 APIs, so these headers won't be combined at all - but that will have to wait until later, and will only apply for Node versions including that change anyway.
Changes
N/A
Features
N/A
Bug Fixes
Breaking Changes and Deprecations
N/A
Status