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

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

Closed
sbellone opened this issue Feb 16, 2023 · 0 comments · Fixed by #1936
Closed

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

sbellone opened this issue Feb 16, 2023 · 0 comments · Fixed by #1936
Assignees
Labels
bug Something isn't working

Comments

@sbellone
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants