Commit 887c5808 authored by indexzero's avatar indexzero

[refactor] Manage our own internal list of Agent instances

parent a1cdf005
...@@ -36,6 +36,11 @@ var util = require('util'), ...@@ -36,6 +36,11 @@ var util = require('util'),
// //
exports.version = [0, 5, 7]; exports.version = [0, 5, 7];
//
// Track our own list of agents internal to `node-http-proxy`
//
var _agents = {};
// //
// ### function _getAgent (host, port, secure) // ### function _getAgent (host, port, secure)
// #### @host {string} Host of the agent to get // #### @host {string} Host of the agent to get
...@@ -45,13 +50,23 @@ exports.version = [0, 5, 7]; ...@@ -45,13 +50,23 @@ exports.version = [0, 5, 7];
// and sets the `maxSockets` property appropriately. // and sets the `maxSockets` property appropriately.
// //
function _getAgent (host, port, secure) { function _getAgent (host, port, secure) {
var agent = !secure ? http.getAgent(host, port) : https.getAgent({ var Agent, id = [host, port].join(':');
if (!port) {
port = secure ? 443 : 80;
}
if (!_agents[id]) {
Agent = secure ? https.Agent : http.Agent;
_agents[id] = new Agent({
host: host, host: host,
port: port port: port,
maxSockets: maxSockets
}); });
}
agent.maxSockets = maxSockets; return _agents[id];
return agent;
} }
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment