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.
'x-BaR',
'yoyoyo',
'Connection',
- 'keep-alive'
+ 'close'
];
var expectHeaders = {
host: 'localhost:' + common.PORT,
'transfer-encoding': 'CHUNKED',
'x-bar': 'yoyoyo',
- connection: 'keep-alive'
+ connection: 'close'
};
var expectRawTrailers = [
'Date',
'Tue, 06 Aug 2013 01:31:54 GMT',
'Connection',
- 'keep-alive',
+ 'close',
'Transfer-Encoding',
'chunked'
];
'Date',
null,
'Connection',
- 'keep-alive',
+ 'close',
'Transfer-Encoding',
'chunked'
];
var expectHeaders = {
date: null,
- connection: 'keep-alive',
+ connection: 'close',
'transfer-encoding': 'chunked'
};
res.rawHeaders[1] = null;