Skip to content

Commit

Permalink
fix(fetch): use semicolon for Cookie header delimiter (nodejs#1906)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and anonrig committed Apr 4, 2023
1 parent 87e5b37 commit be9866b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ class HeadersList {

// 2. Append (name, value) to list.
if (exists) {
this[kHeadersMap].set(lowercaseName, { name: exists.name, value: `${exists.value}, ${value}` })
const delimiter = lowercaseName === 'cookie' ? '; ' : ', '
this[kHeadersMap].set(lowercaseName, {
name: exists.name,
value: `${exists.value}${delimiter}${value}`
})
} else {
this[kHeadersMap].set(lowercaseName, { name, value })
}
Expand Down
19 changes: 19 additions & 0 deletions test/fetch/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@ test('Can send cookies to a server with fetch - issue #1463', async (t) => {

t.end()
})

test('Cookie header is delimited with a semicolon rather than a comma - issue #1905', async (t) => {
t.plan(1)

const server = createServer((req, res) => {
t.equal(req.headers.cookie, 'FOO=lorem-ipsum-dolor-sit-amet; BAR=the-quick-brown-fox')
res.end()
}).listen(0)

t.teardown(server.close.bind(server))
await once(server, 'listening')

await fetch(`http://localhost:${server.address().port}`, {
headers: [
['cookie', 'FOO=lorem-ipsum-dolor-sit-amet'],
['cookie', 'BAR=the-quick-brown-fox']
]
})
})

0 comments on commit be9866b

Please sign in to comment.