On this page

Extends: undici.Dispatcher

Agent allows dispatching requests against multiple different origins.

Requests are not guaranteed to be dispatched in order of invocation.

new undici.Agent(options?): void

Arguments:

  • options AgentOptions (optional)

Returns: Agent

Extends: PoolOptions

  • factory (origin: URL, opts: Object) => Dispatcher - Default: (origin, opts) => new Pool(origin, opts)
  • maxOrigins number (optional) - Default: Infinity - Limits the total number of origins that can receive requests at a time, throwing an MaxOriginsReachedError error when attempting to dispatch when the max is reached. If Infinity, no limit is enforced.
Note

Like Pool, Agent inherits all ClientOptions. allowH2 defaults to true and maxConcurrentStreams to 100. The per-origin Pool it creates uses the default unlimited connections, so concurrent requests to the same origin land on separate Client instances and separate TCP/TLS sockets — HTTP/2 multiplexing on a shared session does not apply unless connections is set to a small value. See PoolOptions.

Implements Client.closed

Implements Client.destroyed

Agent.close(callback?): void

Implements Dispatcher.close([callback]).

Agent.destroy(error?, callback?): void

Implements Dispatcher.destroy([error, callback]).

Agent.dispatch(options, handler: AgentDispatchOptions): void

Implements Dispatcher.dispatch(options, handler).

Extends: DispatchOptions

  • origin string | URL

Implements Dispatcher.destroy([error, callback]).

Agent.connect(options, callback?): void

See Dispatcher.connect(options[, callback]).

Agent.dispatch(options, handler): void

Implements Dispatcher.dispatch(options, handler).

Agent.pipeline(options, handler): void

See Dispatcher.pipeline(options, handler).

Agent.request(options, callback?): void

See Dispatcher.request(options [, callback]).

Agent.stream(options, factory, callback?): void

See Dispatcher.stream(options, factory[, callback]).

Agent.upgrade(options, callback?): void

See Dispatcher.upgrade(options[, callback]).

Agent.stats(): void

Returns an object of stats by origin in the format of Record<string, TClientStats | TPoolStats>

See PoolStats and ClientStats.