Skip to content

Set-Cookie header gets concatenated in fetch if an interceptor is in place #4389

@hexchain

Description

@hexchain

Bug Description

If the dispatcher contains an interceptor, even a dummy one, the Set-Cookie headers will be concatenated together.

Reproducible By

const http = require('node:http')
const {Agent} = require('undici');

const dispatcher = new Agent().compose((dispatch) => dispatch)

const server = http.createServer((req, res) => {
    res.writeHead(200, [['set-cookie', 'a=1'], ['set-cookie', 'b=2'], ['set-cookie', 'c=3']])
    res.end("ok")
})
server.listen({port: 3002}, () => {
    Promise.all([fetch('http://localhost:3002'), fetch('http://localhost:3002', {dispatcher})])
        .then(([r1, r2]) => {
            console.log(r1.headers.getSetCookie())
            console.log(r2.headers.getSetCookie())
        })
        .then(() => server.close())
});

The output will be:

[ 'a=1', 'b=2', 'c=3' ]
[ 'a=1,b=2,c=3' ]

Expected Behavior

The two outputs should be identical.

Environment

Nodejs 24.4.1
Undici 7.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions