Skip to content

Commit 2077bd0

Browse files
committed
need separate agent for http/https
1 parent 6c6dddd commit 2077bd0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/configproxy.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ class ConfigurableProxy extends EventEmitter {
173173
});
174174
}
175175
options.ws = true;
176-
this.agent = options.agent = new http.Agent({ keepAlive: true });
177176
var proxy = (this.proxy = httpProxy.createProxyServer(options));
178177

179178
// tornado-style regex routing,
@@ -220,9 +219,14 @@ class ConfigurableProxy extends EventEmitter {
220219
this.metricsServer = http.createServer(metricsCallback);
221220
}
222221

222+
// need separate agents for http and https requests
223+
// these agents allow our _upstream_ sockets to be kept alive
224+
this.httpAgent = http.globalAgent = new http.Agent({ keepAlive: true });
225+
this.httpsAgent = https.globalAgent = new https.Agent({ keepAlive: true });
226+
227+
// these settings configure requests to the proxy itself to accept keep-alive
223228
var httpOptions = {
224229
keepAlive: true,
225-
agent: this.agent,
226230
keepAliveTimeout: this.options.keepAliveTimeout || 5000,
227231
};
228232

@@ -560,7 +564,13 @@ class ConfigurableProxy extends EventEmitter {
560564
}
561565

562566
// add config argument
563-
args.push({ target: target });
567+
var proxyOptions = { target: target };
568+
if (target.protocol.slice(-2) === "s:") {
569+
proxyOptions.agent = that.httpsAgent;
570+
} else {
571+
proxyOptions.agent = that.httpAgent;
572+
}
573+
args.push(proxyOptions);
564574

565575
// add error handling
566576
args.push(function (e) {

0 commit comments

Comments
 (0)