From 76d16f4dd5a9df64c67d8f9d9b38eb3317752429 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Fri, 14 Mar 2014 11:03:35 -0700 Subject: [PATCH] moved agent creation logic into methods on the HttpConnection class, so that subclasses can more easily modify this behavior --- src/lib/connectors/http.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/lib/connectors/http.js b/src/lib/connectors/http.js index 8c514fe69..7975b8173 100644 --- a/src/lib/connectors/http.js +++ b/src/lib/connectors/http.js @@ -41,20 +41,7 @@ function HttpConnector(host, config) { maxSockets: 11 }); - var Agent = this.hand.Agent; // the class - if (config.forever) { - config.keepAlive = config.forever; - } - - if (config.keepAlive) { - Agent = this.host.protocol === 'https' ? ForeverAgent.SSL : ForeverAgent; - this.on('status set', this.bound.onStatusSet); - } - - this.agent = new Agent({ - maxSockets: config.maxSockets, - minSockets: config.minSockets - }); + this.agent = this.createAgent(config); } _.inherits(HttpConnector, ConnectionAbstract); @@ -81,6 +68,28 @@ HttpConnector.prototype.onStatusSet = _.handler(function (status) { } }); +HttpConnector.prototype.createAgent = function (config) { + var Agent = this.hand.Agent; // the class + + if (config.forever) { + config.keepAlive = config.forever; + } + + if (config.keepAlive) { + Agent = this.host.protocol === 'https' ? ForeverAgent.SSL : ForeverAgent; + this.on('status set', this.bound.onStatusSet); + } + + return new Agent(this.makeAgentConfig(config)); +}; + +HttpConnector.prototype.makeAgentConfig = function (config) { + return { + maxSockets: config.maxSockets, + minSockets: config.minSockets + }; +}; + HttpConnector.prototype.makeReqParams = function (params) { params = params || {}; var host = this.host;