summaryrefslogtreecommitdiff
path: root/lib/_http_client.js
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-08-17 18:50:59 -0700
committerisaacs <i@izs.me>2013-09-04 11:19:39 -0700
commit15a5a4a9453a056b783c7ff0966e31c3c6b7d7e1 (patch)
tree4c66bc29fb29aeaaf796473f8ede7ce7789f68b5 /lib/_http_client.js
parent689e5c9d3db67ccfb81a1caefb04176c41a17744 (diff)
downloadnode-new-15a5a4a9453a056b783c7ff0966e31c3c6b7d7e1.tar.gz
http: Only send connection:keep-alive if necessary
In cases where the Agent has maxSockets=Infinity, and keepAlive=false, there's no case where we won't immediately close the connection after the response is completed. Since we're going to close it anyway, send a `connection:close` header rather than a `connection:keep-alive` header. Still send the `connection:keep-alive` if the agent will actually reuse the socket, however. Closes #5838
Diffstat (limited to 'lib/_http_client.js')
-rw-r--r--lib/_http_client.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js
index 63f5ee9565..a1dc3bef0a 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -107,9 +107,18 @@ function ClientRequest(options, cb) {
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;
+ // If there is an agent we should default to Connection:keep-alive,
+ // but only if the Agent will actually reuse the connection!
+ // If it's not a keepAlive agent, and the maxSockets==Infinity, then
+ // there's never a case where this socket will actually be reused
+ var agent = self.agent;
+ if (!agent.keepAlive && !Number.isFinite(agent.maxSockets)) {
+ self._last = true;
+ self.shouldKeepAlive = false;
+ } else {
+ self._last = false;
+ self.shouldKeepAlive = true;
+ }
self.agent.addRequest(self, options);
} else {
// No agent, default to Connection:close.