undici creates its underlying sockets through a connector function. In most cases this happens automatically, butDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/undici/llms.txt
Use this file to discover all available pages before exploring further.
buildConnector lets you intercept the socket creation process — useful for custom TLS verification, certificate pinning, Unix domain socket connections, or injecting custom socket logic.
buildConnector(options)
Creates a connector function with the given TLS and socket options.
BuildOptions
All Node.js TLS options are supported, plus:An IPC endpoint — Unix domain socket path or Windows named pipe. Default:
null.Maximum number of TLS sessions to cache for reuse. Set to
0 to disable TLS session caching. Default: 100.Connection timeout in milliseconds. Default:
10000 (10 seconds).Override the TLS SNI server name.
If
false, disables TLS certificate validation. Useful for self-signed certificates in development. Default: true.Connector function parameters
The returned connector function accepts:The target hostname.
The target host (may differ from hostname).
The protocol (
http: or https:).The target port.
Override the TLS SNI server name for this connection.
The local network address the socket should bind to.
Establish a secure TLS connection over an existing socket (TLS upgrade only).
Basic example
UsebuildConnector to add custom post-connection logic:
Basic custom connector
Certificate fingerprint pinning
Verify the server’s certificate fingerprint to prevent MITM attacks:Certificate fingerprint validation
Using the connect option on Agent
Pass aconnect option (either a ConnectOptions object or a custom connector function) directly to Client, Pool, or Agent:
Custom TLS on Agent
Unix domain sockets
Connect to a server over a Unix socket instead of TCP:Unix socket connection