Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(headers): a single set-cookie #2903

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
add unit test
  • Loading branch information
Uzlopak committed Mar 3, 2024
commit a98a09a771edb18a91ba822e0ae9d9bdd0f94bf5
18 changes: 17 additions & 1 deletion test/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ test('Headers.prototype.getSetCookie', async (t) => {
})

// https://github.com/nodejs/undici/issues/1935
await t.test('When Headers are cloned, so are the cookies', async (t) => {
await t.test('When Headers are cloned, so are the cookies (single entry)', async (t) => {
const server = createServer((req, res) => {
res.setHeader('Set-Cookie', 'test=onetwo')
res.end('Hello World!')
Expand All @@ -709,6 +709,22 @@ test('Headers.prototype.getSetCookie', async (t) => {
assert.deepStrictEqual(res.headers.getSetCookie(), ['test=onetwo'])
assert.ok('set-cookie' in entries)
})

await t.test('When Headers are cloned, so are the cookies (multiple entries)', async (t) => {
const server = createServer((req, res) => {
res.setHeader('Set-Cookie', ['test=onetwo', 'test=onetwothree'])
res.end('Hello World!')
}).listen(0)

await once(server, 'listening')
t.after(closeServerAsPromise(server))

const res = await fetch(`http://localhost:${server.address().port}`)
const entries = Object.fromEntries(res.headers.entries())

assert.deepStrictEqual(res.headers.getSetCookie(), ['test=onetwo', 'test=onetwothree'])
assert.ok('set-cookie' in entries)
})
})

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