fix(network): preserve dates in response headers - #42734
Devin Rousso (dcrousso) wants to merge 1 commit into
Conversation
response header parsing corrupts HTTP dates and macOS WebKit `Set-Cookie` values preserve date headers and only split combined cookies before another cookie pair
| for (const header of headers) { | ||
| const separator = header.name.toLowerCase() === 'set-cookie' ? '\n' : ','; | ||
| const tokens = header.value.split(separator).map(s => s.trim()); | ||
| const tokens = splitHeaderValue(header.name, header.value, separator).map(s => s.trim()); |
There was a problem hiding this comment.
For Firefox we don't need to guess. nsIHttpChannel.visitOriginalResponseHeaders returns headers unmerged, in the order received from the peer. Synthesized headers from route.fulfill go through ParseHeaderLine -> SetHeaderFromNet, so they are visited too. Switching responseHead() in juggler NetworkObserver.js to it makes parseMultivalueHeaders unnecessary and also fixes WWW-Authenticate/Proxy-Authenticate, which Gecko merges with \n and we currently split on comma.
That needs a Firefox roll, so fine to land the heuristic first, but let's not treat this as the Firefox fix.
| export function splitHeaderValue(name: string, value: string, separator: string): string[] { | ||
| if (separator === ',') { | ||
| switch (name.toLowerCase()) { | ||
| case 'date': |
There was a problem hiding this comment.
Let's use Chromium's non-coalescing list (HttpUtil::IsNonCoalescingHeader) instead: date, expires, last-modified, location, retry-after, set-cookie, www-authenticate, proxy-authenticate, strict-transport-security.
location (commas in query strings) and the auth challenges are real breakages that this list misses. if-modified-since, if-unmodified-since and if-range are request headers; every caller passing a separator handles response headers, so they are dead entries.
| return result; | ||
| } | ||
|
|
||
| export function splitHeaderValue(name: string, value: string, separator: string): string[] { |
There was a problem hiding this comment.
The separator === ',' guard makes the coupling between the name switch and the separator implicit. Suggest keeping plain split('\n') for the raw-header paths and giving the comma path its own splitCommaSeparatedHeader(name, value).
Yury Semikhatsky (yury-s)
left a comment
There was a problem hiding this comment.
This looks risky overall for an issue that we haven't heard any complaints about.
Test results for "MCP"1 failed 8563 passed, 1446 skipped Merge workflow run. |
Test results for "tests 1"1 failed 9 flaky51734 passed, 1247 skipped Merge workflow run. |
🟢 The one failure is a known Windows/Firefox flake — this PR is clearHi, I'm the Playwright bot and I triaged the failing CI run.
DetailsPre-existing flake / infra
This PR only changes Triaged by the Playwright bot - agent run |
🟢 Both failures are pre-existing — this PR is clearHi, I'm the Playwright bot and I triaged the two red tests. Neither touches the header-splitting change: the storage-state one fails on DetailsPre-existing flake / infra
Why the diff can't reach either
Triaged by the Playwright bot - agent run |
|
discussed offline and this should really be fixed upstream |
response header parsing corrupts HTTP dates and macOS WebKit
Set-Cookievaluespreserve date headers and only split combined cookies before another cookie pair
fixes #42687