Skip to content

Commit 9ed9c82

Browse files
replace agent: false by internal agent
agent: false option had been set in order not to use the globalAgent which may be set to a proxy agent pointing to the currently running proxy. But it also disable request pooling: https://nodejs.org/api/http.html#http_http_request_options_callback This commit fix this by setting agent to an internal agent (tweakable through options httpAgent and httpsAgent)
1 parent ac4570d commit 9ed9c82

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/proxy.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Proxy.prototype.listen = function(options) {
4545
this.silent = !!options.silent;
4646
this.httpPort = options.port || 8080;
4747
this.timeout = options.timeout || 0;
48+
this.httpAgent = options.httpAgent || new http.Agent();
49+
this.httpsAgent = options.httpsAgent || new https.Agent();
4850
this.sslCaDir = options.sslCaDir || path.resolve(process.cwd(), '.http-mitm-proxy');
4951
this.ca = new ca(this.sslCaDir);
5052
this.sslServers = {};
@@ -470,7 +472,7 @@ Proxy.prototype._onWebSocketServerConnect = function(isSSL, ws) {
470472
}
471473
ctx.proxyToServerWebSocketOptions = {
472474
url: url,
473-
agent: false,
475+
agent: ctx.isSSL ? httpsAgent : httpAgent,
474476
headers: ptosHeaders
475477
};
476478
return self._onWebSocketConnection(ctx, function(err) {
@@ -577,7 +579,7 @@ Proxy.prototype._onHttpServerRequest = function(isSSL, clientToProxyRequest, pro
577579
host: hostPort.host,
578580
port: hostPort.port,
579581
headers: ctx.clientToProxyRequest.headers,
580-
agent: false
582+
agent: ctx.isSSL ? httpsAgent : httpAgent
581583
};
582584
return self._onRequest(ctx, function(err) {
583585
if (err) {

0 commit comments

Comments
 (0)