Skip to content

Headers iterator throws when the response contains a Set-Cookie #1935

@sbellone

Description

@sbellone

Bug Description

#1915 introduced a bug on Headers iterator, which now throws an error when the response contains a Set-Cookie header.

(Also, getSetCookie() returns an empty array for me)

Reproducible By

const express = require('express');
const undici = require('undici');

const app = express();
const port = 3000;
const URL = `http://localhost:${port}/`;

app.get('/', (req, res) => {
  res.setHeader('Set-Cookie', 'test=onetwo');
  res.send('Hello World!');
});
const serv = app.listen(port);

(async () => {
  const res = await undici.fetch(URL);
  // console.log(res.headers.getSetCookie()); // []

  for (const entry of res.headers.entries()) {
    console.log(entry);
  }

  serv.close();
})();

Expected Behavior

See arrays of key/values logged on the console (it works with Undici 5.18.0):

[ 'connection', 'keep-alive' ]
[ 'content-length', '12' ]
...

Logs & Screenshots

~/tests/node_modules/undici/lib/fetch/headers.js:430
        for (const value of cookies) {
                            ^

TypeError: cookies is not iterable
    at get [headers map sorted] (~/tests/node_modules/undici/lib/fetch/headers.js:430:29)
    at ~/tests/node_modules/undici/lib/fetch/headers.js:476:21
    at Headers Iterator.next (~/tests/node_modules/undici/lib/fetch/util.js:731:22)
    at ~/tests/fetch-undici-2.js:18:14
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Environment

Undici 5.19.1
Node v18.14.0

Metadata

Metadata

Assignees

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