From 103990b64043b980cf98feefcae12019ae6e3108 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Mon, 15 Aug 2011 13:51:20 -0700 Subject: [PATCH] Fixes #1531 --- lib/http2.js | 14 +++++++++++--- lib/https2.js | 11 +++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/http2.js b/lib/http2.js index 5196dfc..716a781 100644 --- a/lib/http2.js +++ b/lib/http2.js @@ -929,7 +929,7 @@ Agent.prototype.addRequest = function(req, host, port) { }; Agent.prototype.createSocket = function(name, host, port) { var self = this; - var s = self.createConnection(port, host); + var s = self.createConnection(port, host, self.options); if (!self.sockets[name]) { self.sockets[name] = []; } @@ -1027,7 +1027,11 @@ function ClientRequest(options, cb) { if (self.socketPath) { self._last = true; self.shouldKeepAlive = false; - self.onSocket(net.createConnection(self.socketPath)); + if (options.createConnection) { + self.onSocket(options.createConnection(self.socketPath)); + } else { + self.onSocket(net.createConnection(self.socketPath)); + } } else if (self.agent) { // If there is an agent we should default to Connection:keep-alive. self._last = false; @@ -1037,7 +1041,11 @@ function ClientRequest(options, cb) { // No agent, default to Connection:close. self._last = true; self.shouldKeepAlive = false; - self.onSocket(net.createConnection(options.port, options.host)); + if (options.createConnection) { + self.onSocket(options.createConnection(options.port, options.host, options)); + } else { + self.onSocket(net.createConnection(options.port, options.host)); + } } self._deferToConnect(null, null, function () { diff --git a/lib/https2.js b/lib/https2.js index 02f3289..c039431 100644 --- a/lib/https2.js +++ b/lib/https2.js @@ -51,12 +51,14 @@ exports.createServer = function(opts, requestListener) { // HTTPS agents. +function createConnection(port, host, options) { + return tls.connect(port, host, options); +}; + function Agent(options) { http.Agent.call(this, options); - this.createConnection = function(port, host) { - return tls.connect(port, host, options); - }; -} + this.createConnection = createConnection; +}; inherits(Agent, http.Agent); Agent.prototype.defaultPort = 443; @@ -69,6 +71,7 @@ exports.request = function(options, cb) { if (options.agent === undefined) { options.agent = globalAgent; } + options.createConnection = createConnection; options.defaultPort = options.defaultPort || 443; return http.request(options, cb); }; -- 2.7.4