Skip to content

Commit e5ecd0b

Browse files
committed
https-proxy-agent: create the proxy socket connection first
Also remove the `host`, `hostname`, and `port` opts from the proxy opts before mixing in. Shouldn't strictly be necessary, but gives me a little bit of piece of mind. Also add comment reminding me about why we mix in the proxy options, since coming back today I had to think about it for a while before remembering why it was necessary (good thing I have tests for it!)
1 parent 4049ff2 commit e5ecd0b

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

https-proxy-agent.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,23 @@ function connect (req, _opts, fn) {
7474
var secureProxy = this.secureProxy;
7575
var secureEndpoint = this.secureEndpoint;
7676

77-
// these `opts` are the connect options to connect to the destination endpoint
78-
var opts = extend({}, proxy, secureEndpoint ? secureDefaults : defaults, _opts);
79-
77+
// create a socket connection to the proxy server
8078
var socket;
8179
if (secureProxy) {
8280
socket = tls.connect(proxy);
8381
} else {
8482
socket = net.connect(proxy);
8583
}
8684

85+
// these `opts` are the connect options to connect to the destination endpoint
86+
// XXX: we mix in the proxy options so that TLS options like
87+
// `rejectUnauthorized` get passed to the destination endpoint as well
88+
var proxyOpts = extend({}, proxy);
89+
delete proxyOpts.host;
90+
delete proxyOpts.hostname;
91+
delete proxyOpts.port;
92+
var opts = extend({}, proxyOpts, secureEndpoint ? secureDefaults : defaults, _opts);
93+
8794
// we need to buffer any HTTP traffic that happens with the proxy before we get
8895
// the CONNECT response, so that if the response is anything other than an "200"
8996
// response code, then we can re-play the "data" events on the socket once the

0 commit comments

Comments
 (0)