-
Notifications
You must be signed in to change notification settings - Fork 50
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
Parse request cookies and response set cookies #111
base: main
Are you sure you want to change the base?
Conversation
lmk what you think @soulgalore! |
lib/entryFromResponse.js
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
This change properly handles the cookies and set-cookies in
requestWillBeSentExtraInfo
andresponseReceivedExtraInfo
respectively. 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