Skip to content

Commit da90836

Browse files
mmaleckibnoordhuis
authored andcommitted
tls http https: don't pollute user's options object
1 parent c6c6f98 commit da90836

3 files changed

Lines changed: 22 additions & 24 deletions

File tree

lib/http.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,14 +1076,16 @@ exports.globalAgent = globalAgent;
10761076
function ClientRequest(options, cb) {
10771077
var self = this;
10781078
OutgoingMessage.call(self);
1079-
self.agent = options.agent;
1080-
options.defaultPort = options.defaultPort || 80;
10811079

1082-
options.port = options.port || options.defaultPort;
1083-
options.host = options.hostname || options.host || 'localhost';
1080+
self.agent = options.agent === undefined ? globalAgent : options.agent;
1081+
1082+
var defaultPort = options.defaultPort || 80;
1083+
1084+
var port = options.port || defaultPort;
1085+
var host = options.hostname || options.host || 'localhost';
10841086

10851087
if (options.setHost === undefined) {
1086-
options.setHost = true;
1088+
var setHost = true;
10871089
}
10881090

10891091
self.socketPath = options.socketPath;
@@ -1102,10 +1104,10 @@ function ClientRequest(options, cb) {
11021104
self.setHeader(key, options.headers[key]);
11031105
}
11041106
}
1105-
if (options.host && !this.getHeader('host') && options.setHost) {
1106-
var hostHeader = options.host;
1107-
if (options.port && +options.port !== options.defaultPort) {
1108-
hostHeader += ':' + options.port;
1107+
if (host && !this.getHeader('host') && setHost) {
1108+
var hostHeader = host;
1109+
if (port && +port !== defaultPort) {
1110+
hostHeader += ':' + port;
11091111
}
11101112
this.setHeader('Host', hostHeader);
11111113
}
@@ -1142,15 +1144,15 @@ function ClientRequest(options, cb) {
11421144
// If there is an agent we should default to Connection:keep-alive.
11431145
self._last = false;
11441146
self.shouldKeepAlive = true;
1145-
self.agent.addRequest(self, options.host, options.port);
1147+
self.agent.addRequest(self, host, port);
11461148
} else {
11471149
// No agent, default to Connection:close.
11481150
self._last = true;
11491151
self.shouldKeepAlive = false;
11501152
if (options.createConnection) {
1151-
var conn = options.createConnection(options.port, options.host, options);
1153+
var conn = options.createConnection(port, host, options);
11521154
} else {
1153-
var conn = net.createConnection(options.port, options.host);
1155+
var conn = net.createConnection(port, host);
11541156
}
11551157
self.onSocket(conn);
11561158
}
@@ -1426,15 +1428,10 @@ exports.request = function(options, cb) {
14261428
throw new Error('Protocol:' + options.protocol + ' not supported.');
14271429
}
14281430

1429-
if (options.agent === undefined) {
1430-
options.agent = globalAgent;
1431-
}
1432-
14331431
return new ClientRequest(options, cb);
14341432
};
14351433

14361434
exports.get = function(options, cb) {
1437-
options.method = 'GET';
14381435
var req = exports.request(options, cb);
14391436
req.end();
14401437
return req;

lib/https.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ exports.request = function(options, cb) {
8383
};
8484

8585
exports.get = function(options, cb) {
86-
options.method = 'GET';
8786
var req = exports.request(options, cb);
8887
req.end();
8988
return req;

lib/tls.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,28 +1061,30 @@ Server.prototype.SNICallback = function(servername) {
10611061
//
10621062
//
10631063
exports.connect = function(/* [port, host], options, cb */) {
1064-
var options = {}, cb;
1064+
var options, port, host, cb;
10651065

10661066
if (typeof arguments[0] === 'object') {
10671067
options = arguments[0];
10681068
} else if (typeof arguments[1] === 'object') {
10691069
options = arguments[1];
1070-
options.port = arguments[0];
1070+
port = arguments[0];
10711071
} else if (typeof arguments[2] === 'object') {
10721072
options = arguments[2];
1073-
options.port = arguments[0];
1074-
options.host = arguments[1];
1073+
port = arguments[0];
1074+
host = arguments[1];
10751075
} else {
10761076
// This is what happens when user passes no `options` argument, we can't
10771077
// throw `TypeError` here because it would be incompatible with old API
10781078
if (typeof arguments[0] === 'number') {
1079-
options.port = arguments[0];
1079+
port = arguments[0];
10801080
}
10811081
if (typeof arguments[1] === 'string') {
1082-
options.host = arguments[1];
1082+
host = arguments[1];
10831083
}
10841084
}
10851085

1086+
options = util._extend({ port: port, host: host }, options || {});
1087+
10861088
if (typeof arguments[arguments.length - 1] === 'function') {
10871089
cb = arguments[arguments.length - 1];
10881090
}

0 commit comments

Comments
 (0)