Skip to content

Commit 103990b

Browse files
mikealry
authored andcommitted
Fixes #1531
1 parent 94963ab commit 103990b

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

lib/http2.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ Agent.prototype.addRequest = function(req, host, port) {
929929
};
930930
Agent.prototype.createSocket = function(name, host, port) {
931931
var self = this;
932-
var s = self.createConnection(port, host);
932+
var s = self.createConnection(port, host, self.options);
933933
if (!self.sockets[name]) {
934934
self.sockets[name] = [];
935935
}
@@ -1027,7 +1027,11 @@ function ClientRequest(options, cb) {
10271027
if (self.socketPath) {
10281028
self._last = true;
10291029
self.shouldKeepAlive = false;
1030-
self.onSocket(net.createConnection(self.socketPath));
1030+
if (options.createConnection) {
1031+
self.onSocket(options.createConnection(self.socketPath));
1032+
} else {
1033+
self.onSocket(net.createConnection(self.socketPath));
1034+
}
10311035
} else if (self.agent) {
10321036
// If there is an agent we should default to Connection:keep-alive.
10331037
self._last = false;
@@ -1037,7 +1041,11 @@ function ClientRequest(options, cb) {
10371041
// No agent, default to Connection:close.
10381042
self._last = true;
10391043
self.shouldKeepAlive = false;
1040-
self.onSocket(net.createConnection(options.port, options.host));
1044+
if (options.createConnection) {
1045+
self.onSocket(options.createConnection(options.port, options.host, options));
1046+
} else {
1047+
self.onSocket(net.createConnection(options.port, options.host));
1048+
}
10411049
}
10421050

10431051
self._deferToConnect(null, null, function () {

lib/https2.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ exports.createServer = function(opts, requestListener) {
5151

5252
// HTTPS agents.
5353

54+
function createConnection(port, host, options) {
55+
return tls.connect(port, host, options);
56+
};
57+
5458
function Agent(options) {
5559
http.Agent.call(this, options);
56-
this.createConnection = function(port, host) {
57-
return tls.connect(port, host, options);
58-
};
59-
}
60+
this.createConnection = createConnection;
61+
};
6062
inherits(Agent, http.Agent);
6163
Agent.prototype.defaultPort = 443;
6264

@@ -69,6 +71,7 @@ exports.request = function(options, cb) {
6971
if (options.agent === undefined) {
7072
options.agent = globalAgent;
7173
}
74+
options.createConnection = createConnection;
7275
options.defaultPort = options.defaultPort || 443;
7376
return http.request(options, cb);
7477
};

0 commit comments

Comments
 (0)