diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 6784e884859986..1b76ac9e93ec9a 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -342,7 +342,11 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) { installListeners(this, s, options); cb(null, s); }); - + // when keepAlive is true, pass the related options to createConnection + if (this.keepAlive) { + options.keepAlive = this.keepAlive; + options.keepAliveInitialDelay = this.keepAliveMsecs; + } const newSocket = this.createConnection(options, oncreate); if (newSocket) oncreate(null, newSocket);