Skip to content

Commit ca44610

Browse files
committed
https-proxy-agent: add support for passing options to net/tls .connect()
Makes passing `rejectUnauthorized: false` work as expected.
1 parent 02a203a commit ca44610

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

https-proxy-agent.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,22 @@ module.exports = HttpsProxyAgent;
2525
function HttpsProxyAgent (opts) {
2626
if (!(this instanceof HttpsProxyAgent)) return new HttpsProxyAgent(opts);
2727
if ('string' == typeof opts) opts = url.parse(opts);
28+
var proxy = clone(opts, {});
2829
Agent.call(this);
29-
this.proxy = opts;
30-
this.secure = this.proxy.protocol && this.proxy.protocol == 'https:';
30+
31+
this.secure = proxy.protocol && proxy.protocol == 'https:';
32+
33+
proxy.host = proxy.hostname || proxy.host;
34+
proxy.port = +proxy.port || (this.secure ? 443 : 80);
35+
36+
if (proxy.host && proxy.path) {
37+
// XXX: if both a `host` and `path` are specified then it's most likely the
38+
// result of a `url.parse()` call... we need to remove the `path` portion so
39+
// that `net.connect()` doesn't attempt to open that as a unix socket file.
40+
delete proxy.path;
41+
}
42+
43+
this.proxy = proxy;
3144
}
3245
inherits(HttpsProxyAgent, Agent);
3346

@@ -45,14 +58,10 @@ Agent.prototype.defaultPort = 443;
4558

4659
HttpsProxyAgent.prototype.createConnection = function (opts, fn) {
4760
var socket;
48-
var info = {
49-
host: this.proxy.hostname || this.proxy.host,
50-
port: +this.proxy.port || (this.secure ? 443 : 80)
51-
};
5261
if (this.secure) {
53-
socket = tls.connect(info);
62+
socket = tls.connect(this.proxy);
5463
} else {
55-
socket = net.connect(info);
64+
socket = net.connect(this.proxy);
5665
}
5766

5867
var msg = 'CONNECT ' + opts.host + ':' + opts.port + ' HTTP/1.1\r\n' +
@@ -76,3 +85,8 @@ HttpsProxyAgent.prototype.createConnection = function (opts, fn) {
7685
fn(null, socket);
7786
};
7887
};
88+
89+
function clone (src, dest) {
90+
for (var i in src) dest[i] = src[i];
91+
return dest;
92+
}

0 commit comments

Comments
 (0)