On this page

An Agent object for HTTPS similar to http.Agent. See https.request() for more information.

Like http.Agent, the createConnection(options[, callback]) method can be overridden to customize how TLS connections are established.

See agent.createConnection() for details on overriding this method, including asynchronous socket creation with a callback.

new Agent(options?): Agent
Attributes
options:Object
Set of configurable options to set on the agent. Can have the same fields as for http.Agent(options), and
maxCachedSessions?:number
maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
servername?:string
the value of Server Name Indication extension to be sent to the server. Use empty string '' to disable sending the extension. Default: host name of the target server, unless the target server is specified using an IP address, in which case the default is '' (no extension).

Requests that specify a custom checkServerIdentity option are not eligible for connection reuse or TLS session reuse by an https.Agent, unless the checkServerIdentity option was specified when constructing the Agent.

E

keylog

History
Attributes
line:Buffer
Line of ASCII text, in NSS SSLKEYLOGFILE format.
tlsSocket:tls.TLSSocket
The tls.TLSSocket instance on which it was generated.

The keylog event is emitted when key material is generated or received by a connection managed by this agent (typically before handshake has completed, but not necessarily). This keying material can be stored for debugging, as it allows captured TLS traffic to be decrypted. It may be emitted multiple times for each socket.

A typical use case is to append received lines to a common text file, which is later used by software (such as Wireshark) to decrypt the traffic:

// ...
https.globalAgent.on('keylog', (line, tlsSocket) => {
  fs.appendFileSync('/tmp/ssl-keys.log', line, { mode: 0o600 });
});