Skip to content

Commit

Permalink
[refactor] Manage our own internal list of Agent instances
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed May 25, 2011
1 parent a1cdf00 commit 887c580
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/node-http-proxy.js
Expand Up @@ -36,6 +36,11 @@ var util = require('util'),
//
exports.version = [0, 5, 7];

//
// Track our own list of agents internal to `node-http-proxy`
//
var _agents = {};

//
// ### function _getAgent (host, port, secure)
// #### @host {string} Host of the agent to get
Expand All @@ -45,13 +50,23 @@ exports.version = [0, 5, 7];
// and sets the `maxSockets` property appropriately.
//
function _getAgent (host, port, secure) {
var agent = !secure ? http.getAgent(host, port) : https.getAgent({
host: host,
port: port
});

agent.maxSockets = maxSockets;
return agent;
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,
port: port,
maxSockets: maxSockets
});
}

return _agents[id];
}

//
Expand Down

0 comments on commit 887c580

Please sign in to comment.