Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/web/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ class HeadersList {
return headers
}

get entriesList () {
const headers = []

if (this[kHeadersMap].size !== 0) {
for (const { 0: lowerName, 1: { name, value } } of this[kHeadersMap]) {
if (lowerName === 'set-cookie') {
for (const cookie of this.cookies) {
headers.push([name, cookie])
}
} else {
headers.push([name, value])
}
}
}

return headers
}

// https://fetch.spec.whatwg.org/#convert-header-names-to-a-sorted-lowercase-set
toSortedArray () {
const size = this[kHeadersMap].size
Expand Down Expand Up @@ -605,7 +623,7 @@ webidl.converters.HeadersInit = function (V) {
// A work-around to ensure we send the properly-cased Headers when V is a Headers object.
// Read https://github.com/nodejs/undici/pull/3159#issuecomment-2075537226 before touching, please.
if (!util.types.isProxy(V) && kHeadersList in V && iterator === Headers.prototype.entries) { // Headers object
return V[kHeadersList].entries
return V[kHeadersList].entriesList
}

if (typeof iterator === 'function') {
Expand Down
6 changes: 6 additions & 0 deletions test/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ test('Headers.prototype.getSetCookie', async (t) => {
assert.deepStrictEqual(res.headers.getSetCookie(), ['test=onetwo', 'test=onetwothree'])
assert.ok('set-cookie' in entries)
})

await t.test('When Headers are cloned, so are the cookies (Headers constructor)', () => {
const headers = new Headers([['set-cookie', 'a'], ['set-cookie', 'b']])

assert.deepStrictEqual([...headers], [...new Headers(headers)])
})
})

test('When the value is updated, update the cache', (t) => {
Expand Down