Skip to content

Commit

Permalink
fix: set-cookie clone (#2446)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx authored and metcoder95 committed Nov 22, 2023
1 parent 16ab2c9 commit 150ed52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class HeadersList {
if (init instanceof HeadersList) {
this[kHeadersMap] = new Map(init[kHeadersMap])
this[kHeadersSortedMap] = init[kHeadersSortedMap]
this.cookies = init.cookies
this.cookies = init.cookies === null ? null : [...init.cookies]
} else {
this[kHeadersMap] = new Map(init)
this[kHeadersSortedMap] = null
Expand Down
10 changes: 10 additions & 0 deletions test/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,14 @@ test('request.referrer', (t) => {
t.end()
})

// https://github.com/nodejs/undici/issues/2445
test('Clone the set-cookie header when Request is passed as the first parameter and no header is passed.', (t) => {
t.plan(2)
const request = new Request('http://localhost', { headers: { 'set-cookie': 'A' } })
const request2 = new Request(request)
request2.headers.append('set-cookie', 'B')
t.equal(request.headers.getSetCookie().join(', '), request.headers.get('set-cookie'))
t.equal(request2.headers.getSetCookie().join(', '), request2.headers.get('set-cookie'))
})

teardown(() => process.exit())

0 comments on commit 150ed52

Please sign in to comment.