Skip to content

Client constructor accepts typed interceptors, but never applies them at runtime #4993

@trivikr

Description

@trivikr

Bug Description

Client.Options publicly exposes interceptors, but Client does not consume that option at runtime.

undici/types/client.d.ts

Lines 32 to 38 in 51cc6cb

export declare namespace Client {
export interface OptionsInterceptors {
Client: readonly Dispatcher.DispatchInterceptor[];
}
export interface Options {
/** TODO */
interceptors?: OptionsInterceptors;

Reproducible By

  • Create a Client with constructor-time interceptors
  • Use an interceptor that increments a counter before forwarding to dispatch.
  • Perform a real request through that client.
  • Observe that the request succeeds, but the interceptor counter remains 0.
import { createServer } from "node:http";
import { once } from "node:events";
import { Client } from "undici";

let calls = 0;

const interceptor = (dispatch) => (opts, handler) => {
  calls++;
  return dispatch(opts, handler);
};

const server = createServer((req, res) => {
  res.end("ok");
});

server.listen(0, "127.0.0.1");
await once(server, "listening");

const { port } = server.address();

const client = new Client(`http://127.0.0.1:${port}`, {
  interceptors: { Client: [interceptor] },
});

const { body } = await client.request({ path: "/", method: "GET" });
await body.text();
await client.close();
server.close();

console.log({ calls });

Expected Behavior

Either:

  • Client should apply constructor-time interceptors.Client entries to its dispatch pipeline, or
  • interceptors should be removed from Client.Options if constructor-time support is not intended.

Logs & Screenshots

Observed output from the repro:

{ calls: 0 }

The request completes successfully; the interceptor is just never invoked.

Environment

macOS (Darwin 25.1.0, arm64) Node.js v24.14.1 undici 8.0.2

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