Skip to content

Commit a48c3e4

Browse files
committed
Merge pull request #61 from joeferner/agent-fix
replace agent: false by internal agent
2 parents ac4570d + a61aabe commit a48c3e4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ __Arguments__
115115
* sslCaDir - Path to the certificates cache directory (default: process.cwd() + '/.http-mitm-proxy')
116116
* silent - if set to true, nothing will be written to console (default: false)
117117
* timeout - The number of milliseconds of inactivity before a socket is presumed to have timed out. Defaults to no timeout.
118+
* httpAgent - The [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent) to use when making http requests. Useful for chaining proxys. Defaults to an internal Agent.
119+
* httpsAgent - The [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) to use when making https requests. Useful for chaining proxys. Defaults to an internal Agent.
118120

119121
__Example__
120122

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 ? self.httpsAgent : self.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 ? self.httpsAgent : self.httpAgent
581583
};
582584
return self._onRequest(ctx, function(err) {
583585
if (err) {

0 commit comments

Comments
 (0)