moved agent creation logic into methods on the HttpConnection class, so that subclasses can more easily modify this behavior

This commit is contained in:
Spencer Alger
2014-03-14 11:03:35 -07:00
parent c4ff168f31
commit 76d16f4dd5

View File

@ -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;