method
http.Agent.createConnection
Produces a socket/stream to be used for HTTP requests.
By default, this function behaves identically to net.createConnection(), synchronously returning the created socket. The optional callback parameter in the signature is not used by this default implementation.
However, custom agents may override this method to provide greater flexibility, for example, to create sockets asynchronously. When overriding createConnection:
- Synchronous socket creation: The overriding method can return the socket/stream directly.
- Asynchronous socket creation: The overriding method can accept the
callbackand pass the created socket/stream to it (e.g.,callback(null, newSocket)). If an error occurs during socket creation, it should be passed as the first argument to thecallback(e.g.,callback(err)).
The agent will call the provided createConnection function with options and this internal callback. The callback provided by the agent has a signature of (err, stream).
Options containing connection details. Check net.createConnection for the format of the options. For custom agents, this object is passed to the custom createConnection function.
(Optional, primarily for custom agents) A function to be called by a custom createConnection implementation when the socket is created, especially for asynchronous operations.
The created socket. This is returned by the default implementation or by a custom synchronous createConnection implementation. If a custom createConnection uses the callback for asynchronous operation, this return value might not be the primary way to obtain the socket.
Referenced types
interface ClientRequestArgs
- createConnection?: (options: ClientRequestArgs, oncreate: (err: null | Error, socket: Duplex) => void) => undefined | null | Duplex
- hints?: number
One or more supported
getaddrinfoflags. Multiple flags may be passed by bitwiseORing their values.