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).
Since
v0.11.4
Parameters
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.