Skip to content

Commit 11e54c8

Browse files
committed
https-proxy-agent: use "extend" module
This allows us to default the "port" in a cleaner manner, as well as we are now mixing in the `proxy` options to the destination server as well. Mixing in the `proxy` options fixes the failing tests on node < node v0.11.6.
1 parent a8be3ed commit 11e54c8

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

https-proxy-agent.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
var net = require('net');
77
var tls = require('tls');
88
var url = require('url');
9+
var extend = require('extend');
910
var Agent = require('agent-base');
1011
var inherits = require('util').inherits;
1112
var debug = require('debug')('https-proxy-agent');
@@ -30,7 +31,7 @@ function HttpsProxyAgent (opts) {
3031
debug('creating new HttpsProxyAgent instance: %j', opts);
3132
Agent.call(this, connect);
3233

33-
var proxy = clone(opts, {});
34+
var proxy = extend({}, opts);
3435

3536
// if `true`, then connect to the proxy server over TLS. defaults to `false`.
3637
this.secureProxy = proxy.protocol ? proxy.protocol == 'https:' : false;
@@ -53,14 +54,20 @@ function HttpsProxyAgent (opts) {
5354
}
5455
inherits(HttpsProxyAgent, Agent);
5556

57+
/**
58+
* Defaults for the "connect" opts object.
59+
*/
60+
61+
var defaults = { port: 443 };
62+
5663
/**
5764
* Called when the node-core HTTP client library is creating a new HTTP request.
5865
*
5966
* @api public
6067
*/
6168

62-
function connect (req, opts, fn) {
63-
if (null == opts.port) opts.port = 443;
69+
function connect (req, _opts, fn) {
70+
var opts = extend({}, this.proxy, defaults, _opts);
6471

6572
var socket;
6673
if (this.secureProxy) {
@@ -112,8 +119,3 @@ function connect (req, opts, fn) {
112119
'\r\n';
113120
socket.write(msg);
114121
};
115-
116-
function clone (src, dest) {
117-
for (var i in src) dest[i] = src[i];
118-
return dest;
119-
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
},
2424
"dependencies": {
2525
"agent-base": "~1.0.1",
26-
"debug": "~0.7.2"
26+
"debug": "~0.7.2",
27+
"extend": "~1.2.0"
2728
},
2829
"devDependencies": {
2930
"mocha": "~1.12.0",

0 commit comments

Comments
 (0)