Skip to content

Commit

Permalink
fix: clear set-cookie headers (nodejs#2052)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and metcoder95 committed Jul 21, 2023
1 parent 1afeb77 commit c76348d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class HeadersList {
clear () {
this[kHeadersMap].clear()
this[kHeadersSortedMap] = null
this.cookies = null
}

// https://fetch.spec.whatwg.org/#concept-header-list-append
Expand Down
16 changes: 16 additions & 0 deletions test/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,19 @@ test('constructing Request with third party FormData body', async (t) => {
t.equal(contentType[0], 'multipart/form-data; boundary')
t.ok((await req.text()).startsWith(`--${contentType[1]}`))
})

// https://github.com/nodejs/undici/issues/2050
test('set-cookie headers get cleared when passing a Request as first param', (t) => {
const req1 = new Request('http://localhost', {
headers: {
'set-cookie': 'a=1'
}
})

t.same([...req1.headers], [['set-cookie', 'a=1']])
const req2 = new Request(req1, { headers: {} })

t.same([...req2.headers], [])
t.same(req2.headers.getSetCookie(), [])
t.end()
})

0 comments on commit c76348d

Please sign in to comment.