Skip to content

DNS interceptor breaks headers of type [string, string][] #4444

@peterhirn

Description

@peterhirn

Bug Description

Unable to use headers of type [string, string][], using Record<string, string> works (see below).

Reproducible By

import http from "node:http";
import { Agent, interceptors, request } from "undici";

const port = process.env.PORT ?? 3001;

const { cache, dns } = interceptors;

const good = new Agent().compose(cache());

const fail = new Agent().compose(cache(), dns());

http
  .createServer((req, res) => {
    console.log(req.headers);
    res.end();
  })
  .listen(port, async () => {
    const headers = [["foo", "bar"]];

    await request(`http://localhost:${port}`, {
      dispatcher: good,
      headers,
    });

    await request(`http://localhost:${port}`, {
      dispatcher: fail,
      headers,
    });

    const headersAsRecord = { foo: "bar" };
    await request(`http://localhost:${port}`, {
      dispatcher: fail,
      headers: headersAsRecord,
    });
  });
node index.js
{ host: 'localhost:3001', connection: 'keep-alive', foo: 'bar' }
{ '0': 'foo, bar', host: 'localhost:3001', connection: 'keep-alive' }
{ host: 'localhost:3001', connection: 'keep-alive', foo: 'bar' }

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