Skip to content

Conversation

hexchain
Copy link
Contributor

@hexchain hexchain commented Aug 6, 2025

This relates to...

#4389

Changes

In httpNetworkFetch->dispatch->onHeaders, append multi-value header values one by one and let HeadersList handle concatenation.

Features

N/A

Bug Fixes

#4389

Breaking Changes and Deprecations

N/A

Status

@hexchain hexchain force-pushed the fix-4389 branch 2 times, most recently from 4c50452 to 6ebaf87 Compare August 7, 2025 05:34
@hexchain hexchain changed the title fix: avoid merging multi-value headers in WrapHandler fix: correctly handle multi-value headers in fetch when rawHeaders contains array Aug 7, 2025
@hexchain
Copy link
Contributor Author

hexchain commented Aug 7, 2025

I've pushed a different fix as discussed in #4390 (comment). Please take a look, thanks!

@hexchain hexchain requested review from Uzlopak and metcoder95 August 8, 2025 07:17
Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

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

code wise, lgtm; but defer to @KhafraDev

@@ -2110,7 +2110,15 @@ async function httpNetworkFetch (
const headersList = new HeadersList()

for (let i = 0; i < rawHeaders.length; i += 2) {
headersList.append(bufferToLowerCasedHeaderName(rawHeaders[i]), rawHeaders[i + 1].toString('latin1'), true)
const nameStr = bufferToLowerCasedHeaderName(rawHeaders[i])
Copy link
Member

Choose a reason for hiding this comment

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

As this only breaks given an interceptor, I'd prefer that we fix it within undici's rather than fetch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My idea is that fetch should properly support arrays of header values in rawHeaders, if such case is valid.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but I'd prefer to cross check with the spec to see what it has to say regarding duplicated headers, if the implementation already aligns, most likely is an undici issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC, RFC 7230 Section 3.2.2 means that:

  • A sender must not send multiple headers with the same name unless it is Set-Cookie,
  • A receiver may combine values of multiple headers with the same name into a comma-separated list, except for Set-Cookie.

I'd say it is fine to have them separated in Undici/interceptor APIs, and only join them in fetch.

Copy link
Contributor

Choose a reason for hiding this comment

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

You refer to RFC7230 but not the fetch spec

@hexchain hexchain requested a review from KhafraDev August 13, 2025 15:27
@hexchain
Copy link
Contributor Author

hexchain commented Sep 7, 2025

Gentle ping. May I have some reviews again?

The latest change only touches fetch and not (Un)wrapHandlers, so no changes to existing interceptor/handler behaviors. Duplicate headers are processed mostly in the same way as before, except when interceptors exist, in which case it is more correct than before - it uses HeadersList.append now instead of Array<Buffer>.toString.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants