Skip to content

Commit 0562e9b

Browse files
authored
fix: clear set-cookie headers (#2052)
1 parent fb84aac commit 0562e9b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/fetch/headers.js

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class HeadersList {
9595
clear () {
9696
this[kHeadersMap].clear()
9797
this[kHeadersSortedMap] = null
98+
this.cookies = null
9899
}
99100

100101
// https://fetch.spec.whatwg.org/#concept-header-list-append

test/fetch/request.js

+16
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,19 @@ test('constructing Request with third party FormData body', async (t) => {
460460
t.equal(contentType[0], 'multipart/form-data; boundary')
461461
t.ok((await req.text()).startsWith(`--${contentType[1]}`))
462462
})
463+
464+
// https://github.com/nodejs/undici/issues/2050
465+
test('set-cookie headers get cleared when passing a Request as first param', (t) => {
466+
const req1 = new Request('http://localhost', {
467+
headers: {
468+
'set-cookie': 'a=1'
469+
}
470+
})
471+
472+
t.same([...req1.headers], [['set-cookie', 'a=1']])
473+
const req2 = new Request(req1, { headers: {} })
474+
475+
t.same([...req2.headers], [])
476+
t.same(req2.headers.getSetCookie(), [])
477+
t.end()
478+
})

0 commit comments

Comments
 (0)