-
-
Notifications
You must be signed in to change notification settings - Fork 674
fix: correctly handle multi-value headers in fetch when rawHeaders contains array
#4390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
4c50452 to
6ebaf87
Compare
rawHeaders contains array
|
I've pushed a different fix as discussed in #4390 (comment). Please take a look, thanks! |
metcoder95
left a comment
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.
code wise, lgtm; but defer to @KhafraDev
|
|
||
| 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]) |
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.
As this only breaks given an interceptor, I'd prefer that we fix it within undici's rather than fetch
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.
My idea is that fetch should properly support arrays of header values in rawHeaders, if such case is valid.
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.
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.
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.
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.
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.
You refer to RFC7230 but not the fetch spec
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.
It seems to me that HTTP-network fetch doesn't really specify how headers should be treated while being received? It merely says:
Follow the relevant requirements from HTTP. [HTTP] [HTTP-CACHING]
Wait until all the HTTP response headers are transmitted.
in which "[HTTP]" refers to RFC9110. In that document, section 5.2 and 5.3 are basically a rephrase of RFC7230 section 3.2.2.
In undici, the relevant code is in httpNetworkFetch->dispatch->onHeaders, and I believe is an implementation detail. IIUC, changes to this part of the code should count as fixing the issue in undici.
|
Gentle ping. May I have some reviews again? The latest change only touches |
mcollina
left a comment
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
metcoder95
left a comment
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.
I'd still suggest to alter the interceptor rather than fetch itself
|
@metcoder95 By "interceptor" do you mean Wrap/UnwrapHandler? There is (almost) no interceptor involved in the original reproducer. |
|
Yes, exactly; sorry for the confusion, was referring to the wrapper |
|
@metcoder95 can you do an alternative PR with that fix? I'm not sure it'd be possible to actually do that. |
|
I believe that was also the very first iteration of this PR. I'll try to summarize the situation and hopefully uncover a clear path forward. The issue happens because the original dispatch handler (which is "old"-style, according to #3878) gets wrapped and unwrapped, so the headers argument of
Please enlighten me if there are better ways. Personally, I think the first idea is more sound but I'm really unsure about adding the header name check. |
This relates to...
#4389
Changes
In
httpNetworkFetch->dispatch->onHeaders, append multi-value header values one by one and letHeadersListhandle concatenation.Features
N/A
Bug Fixes
#4389
Breaking Changes and Deprecations
N/A
Status