Skip to content

Undici v8 drops headers when using Undici v7 Agent #5341

@QuiiBz

Description

@QuiiBz

Bug Description

Using Node.js 26 with Undici v8's fetch alongside a Undici v7 Agent dispatcher causes responses to drop their headers, including content-type / content-encoding, which would cause the body to not be decompressed for example

Reproducible By

import { createServer } from "node:http";
import { brotliCompressSync } from "node:zlib";
import { Agent } from "undici";

const body = Buffer.from('body content');
const compressedBody = brotliCompressSync(body);

const server = createServer((_request, response) => {
  response.writeHead(200, {
    "content-type": "application/x-ndjson",
    "content-encoding": "br",
    "another-test-header": "test-value",
  });
  response.end(compressedBody);
});

await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));

const { port } = server.address();
const url = `http://127.0.0.1:${port}/`;
const agent = new Agent();

async function run(label, init) {
  const response = await fetch(url, init);
  const body = Buffer.from(await response.arrayBuffer());
  console.log('---', label, '---');
  console.log('Response headers', response.headers);
  console.log('Body', body.toString());
}

console.log('Using Node.js', process.version, 'with bundled fetch Undici', process.versions.undici);
await run("No dispatcher", {});
await run("Undici v7 dispatcher", { dispatcher: agent });
server.close();

Running using Node.js 24, both versions with or without using Undici v7 dispatcher work as expected:

proto run node 24.16.0 -- repro.js
Image

Running using Node.js 26, not using the Undici v7 dispatcher works but using it causes the response to loose its headers and the body to not be decompressed:

proto run node 26.3.0 -- repro.js
Image

Expected Behavior

Using a Undici v7 Agent with Undici v8's fetch should either not drop the response headers (like when using Undici v7's fetch), or explicitely error at runtime before making a request if that combinaison is not supported. This can happen easily for applications or libraries installing Undici v7 explicitly (since Node.js' bundled Undici doesn't explicitly expose the Agent class) while routinely upgrading the app from Node.js 24 to 26

Logs & Screenshots

Shared above

Environment

Any Node.js 26 environment with Undici v7 installed

Additional context

I found this while investigating an upstream issue: vercel/sandbox#198

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions