Repository navigation
Conversation
|
lmk what you think @soulgalore! |
| // Merging and de-duplicating because extraResponse headers contain the original response headers as well | ||
| if (entry.extraResponseInfo.headers) { | ||
| const mergedHeaders = new Set( | ||
| [...headers, ...entry.extraResponseInfo.headers].map(JSON.stringify) | ||
| ); | ||
| headers = Array.from(mergedHeaders, JSON.parse); | ||
| } |
There was a problem hiding this comment.
This is the only section that really jumped out to me (not a maintainer).
Is it possible that extraResponseInfo.headers always includes all of headers? if so, we can avoid all of this computation and just use that, yes?
I don't think we can rely on unique header names, so this solution certainly works.
Per RFC7230 3.2.2:
A sender MUST NOT generate multiple header fields with the same field
name in a message unless either the entire field value for that
header field is defined as a comma-separated list [i.e., #(values)]
or the header field is a well-known exception (as noted below).A recipient MAY combine multiple header fields with the same field
name into one "field-name: field-value" pair, without changing the
semantics of the message, by appending each subsequent field value to
the combined field value in order, separated by a comma. The order
in which header fields with the same field name are received is
therefore significant to the interpretation of the combined field
value; a proxy MUST NOT change the order of these field values when
forwarding a message.
The only thing I could think of that might work better (and here we'd need some performance tests) is to use a Map instead.:
const list = [
{name: 'a', value: 1},
{name: 'a', value: 2},
{name: 'b', value: 1},
{name: 'b', value: 1},
]
function makeUniqueSet(list) {
const map = new Map()
list.forEach(l => map.set(`${l.name}-${l.value}`, l))
const uniqueSet = [...map.values()]
return uniqueSet;
}There was a problem hiding this comment.
Thanks Stephen! Made use of your suggestion and updated the PR. Will leave this comment open though to see if @soulgalore thinks this step is even necessary.
|
Thanks @jtung23 I'll have a look this weekend. |
|
Hi @soulgalore, just wanted to follow up and see if you're able to review this PR. Our team would love to be able to view cookies in the HAR for our debugging purposes! Thanks in advance! |
Chrome sends the real network headers and cookies in separate extra info events. They were handled in a way that gave wrong HARs: headers were appended so the same header showed up twice with different case, response cookies set only in the extra info were missing, and extra info that arrived before the first page event (the normal order with Puppeteer) was dropped, so those requests lost their cookies and most headers. When the server answered a revalidation with a 304, its few headers replaced the headers of the 200 that Chrome served from cache. That removed headers like content-type and content-encoding, which tools like the Coach use to check compression and caching. Headers are now merged, with the extra info winning, and extra info for a response with another status is ignored. Timings, sizes and the number of pages and entries do not change. Based on the first implementation and the test case by jtung23 in #111. Assisted-by: Claude Opus 5.5 [email protected]
This change properly handles the cookies and set-cookies in
requestWillBeSentExtraInfoandresponseReceivedExtraInforespectively. The methods were skipping instead of finding the request entries already stored before the page loads.My use case is puppeteer where the request structure is