diff options
author | isaacs <i@izs.me> | 2013-05-22 18:44:24 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-07-09 22:31:11 -0700 |
commit | 49519f121787d51394f00c871f854794e409bdda (patch) | |
tree | a0e40fb168563401ec401ce7e08098c24d212abc /lib/_http_client.js | |
parent | 40e92650bb97b736b8e29c5de35c1c29ebd625ef (diff) | |
download | node-new-49519f121787d51394f00c871f854794e409bdda.tar.gz |
http: Reuse more http/https Agent code
Diffstat (limited to 'lib/_http_client.js')
-rw-r--r-- | lib/_http_client.js | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js index 0f55148b83..0bc78ab1a4 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -99,33 +99,26 @@ function ClientRequest(options, cb) { self._storeHeader(self.method + ' ' + self.path + ' HTTP/1.1\r\n', self._renderHeaders()); } + if (self.socketPath) { self._last = true; self.shouldKeepAlive = false; - if (options.createConnection) { - self.onSocket(options.createConnection(self.socketPath)); - } else { - self.onSocket(net.createConnection(self.socketPath)); - } + var conn = self.agent.createConnection({ path: self.socketPath }); + self.onSocket(conn); } else if (self.agent) { // If there is an agent we should default to Connection:keep-alive. self._last = false; self.shouldKeepAlive = true; - self.agent.addRequest(self, host, port, options.localAddress); + self.agent.addRequest(self, options); } else { // No agent, default to Connection:close. self._last = true; self.shouldKeepAlive = false; if (options.createConnection) { - options.port = port; - options.host = host; var conn = options.createConnection(options); } else { - var conn = net.createConnection({ - port: port, - host: host, - localAddress: options.localAddress - }); + debug('CLIENT use net.createConnection', options); + var conn = net.createConnection(options); } self.onSocket(conn); } @@ -134,8 +127,8 @@ function ClientRequest(options, cb) { self._flush(); self = null; }); - } + util.inherits(ClientRequest, OutgoingMessage); exports.ClientRequest = ClientRequest; |