Skip to content

Commit 887c580

Browse files
committed
[refactor] Manage our own internal list of Agent instances
1 parent a1cdf00 commit 887c580

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lib/node-http-proxy.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ var util = require('util'),
3636
//
3737
exports.version = [0, 5, 7];
3838

39+
//
40+
// Track our own list of agents internal to `node-http-proxy`
41+
//
42+
var _agents = {};
43+
3944
//
4045
// ### function _getAgent (host, port, secure)
4146
// #### @host {string} Host of the agent to get
@@ -45,13 +50,23 @@ exports.version = [0, 5, 7];
4550
// and sets the `maxSockets` property appropriately.
4651
//
4752
function _getAgent (host, port, secure) {
48-
var agent = !secure ? http.getAgent(host, port) : https.getAgent({
49-
host: host,
50-
port: port
51-
});
52-
53-
agent.maxSockets = maxSockets;
54-
return agent;
53+
var Agent, id = [host, port].join(':');
54+
55+
if (!port) {
56+
port = secure ? 443 : 80;
57+
}
58+
59+
if (!_agents[id]) {
60+
Agent = secure ? https.Agent : http.Agent;
61+
62+
_agents[id] = new Agent({
63+
host: host,
64+
port: port,
65+
maxSockets: maxSockets
66+
});
67+
}
68+
69+
return _agents[id];
5570
}
5671

5772
//

0 commit comments

Comments
 (0)