callback to the Server's `'timeout'` event, then you are responsible
for handling socket timeouts.
+Returns `server`.
+
### server.timeout
* {Number} Default = 120000 (2 minutes)
`'timeout'` events, then it is your responsibility to handle timed out
sockets.
+Returns `response`.
+
### response.statusCode
When using implicit headers (not calling [response.writeHead()][] explicitly),
Once a socket is assigned to this request and is connected
[socket.setTimeout()][] will be called.
+Returns `request`.
+
### request.setNoDelay([noDelay])
Once a socket is assigned to this request and is connected
Calls `message.connection.setTimeout(msecs, callback)`.
+Returns `message`.
+
### message.method
**Only valid for request obtained from [http.Server][].**
- `localPort`: Local port to bind to for network connections.
- `family` : Version of IP stack. Defaults to `4`.
-
+
- `lookup` : Custom lookup function. Defaults to `dns.lookup`.
For local domain sockets, `options` argument should be an object which
The optional `callback` parameter will be added as a one time listener for the
`'timeout'` event.
+Returns `socket`.
+
### socket.setNoDelay([noDelay])
Disables the Nagle algorithm. By default TCP connections use the Nagle
this.socket.setTimeout(0, this.timeoutCb);
this.timeoutCb = emitTimeout;
this.socket.setTimeout(msecs, emitTimeout);
- return;
+ return this;
}
// Set timeoutCb so that it'll get cleaned up on request end
this.socket.once('connect', function() {
sock.setTimeout(msecs, emitTimeout);
});
- return;
+ return this;
}
this.once('socket', function(sock) {
sock.setTimeout(msecs, emitTimeout);
});
+
+ return this;
};
ClientRequest.prototype.setNoDelay = function() {
if (callback)
this.on('timeout', callback);
this.socket.setTimeout(msecs);
+ return this;
};
} else {
this.socket.setTimeout(msecs);
}
+ return this;
};
this.timeout = msecs;
if (callback)
this.on('timeout', callback);
+ return this;
};
this.once('timeout', callback);
}
}
+ return this;
};
function destroy() {
req.destroy();
}
- req.setTimeout(1, destroy);
+ var s = req.setTimeout(1, destroy);
+ assert.ok(s instanceof http.ClientRequest);
req.on('error', destroy);
req.end();
});
// just do nothing, we should get a timeout event.
});
server.listen(common.PORT);
- server.setTimeout(50, function(socket) {
+ var s = server.setTimeout(50, function(socket) {
caughtTimeout = true;
socket.destroy();
server.close();
cb();
});
+ assert.ok(s instanceof http.Server);
http.get({ port: common.PORT }).on('error', function() {});
});
});
var server = http.createServer(function(req, res) {
// just do nothing, we should get a timeout event.
- req.setTimeout(50, function() {
+ var s = req.setTimeout(50, function() {
caughtTimeout = true;
req.socket.destroy();
server.close();
cb();
});
+ assert.ok(s instanceof http.IncomingMessage);
});
server.listen(common.PORT);
var req = http.request({ port: common.PORT, method: 'POST' });
});
var server = http.createServer(function(req, res) {
// just do nothing, we should get a timeout event.
- res.setTimeout(50, function() {
+ var s = res.setTimeout(50, function() {
caughtTimeout = true;
res.socket.destroy();
server.close();
cb();
});
+ assert.ok(s instanceof http.OutgoingMessage);
});
server.listen(common.PORT);
http.get({ port: common.PORT }).on('error', function() {});
});
var server = http.createServer(function(req, res) {
// just do nothing, we should get a timeout event.
- req.setTimeout(50, function(socket) {
+ var s = req.setTimeout(50, function(socket) {
caughtTimeoutOnRequest = true;
});
+ assert.ok(s instanceof http.IncomingMessage);
res.on('timeout', function(socket) {
caughtTimeoutOnResponse = true;
});
assert.equal(caughtTimeout, '/2');
});
var server = http.createServer(function(req, res) {
- res.setTimeout(50, function() {
+ var s = res.setTimeout(50, function() {
caughtTimeout += req.url;
});
+ assert.ok(s instanceof http.OutgoingMessage);
if (req.url === '/1') res.end();
});
server.on('timeout', function(socket) {
});
res.end();
});
- server.setTimeout(50, function(socket) {
+ var s = server.setTimeout(50, function(socket) {
caughtTimeoutOnServer = true;
socket.destroy();
server.close();
cb();
});
+ assert.ok(s instanceof http.Server);
server.listen(common.PORT);
var c = net.connect({ port: common.PORT, allowHalfOpen: true }, function() {
c.write('GET /1 HTTP/1.1\r\nHost: localhost\r\n\r\n');
var common = require('../common');
var assert = require('assert');
var http = require('http');
+var net = require('net');
var server = http.createServer(function(req, res) {
console.log('got request. setting 1 second timeout');
- req.connection.setTimeout(500);
-
+ var s = req.connection.setTimeout(500);
+ assert.ok(s instanceof net.Socket);
req.connection.on('timeout', function() {
req.connection.destroy();
common.debug('TIMEOUT');
// just do nothing, we should get a timeout event.
});
server.listen(common.PORT);
- server.setTimeout(50, function(socket) {
+ var s = server.setTimeout(50, function(socket) {
caughtTimeout = true;
socket.destroy();
server.close();
cb();
});
+ assert.ok(s instanceof https.Server);
https.get({
port: common.PORT,
rejectUnauthorized: false
var server = https.createServer(options, assert.fail);
server.on('secureConnection', function(cleartext) {
- cleartext.setTimeout(50, function() {
+ var s = cleartext.setTimeout(50, function() {
cleartext.destroy();
server.close();
});
+ assert.ok(s instanceof tls.TLSSocket);
});
server.listen(common.PORT, function() {
killers.forEach(function(killer) {
var socket = net.createConnection(common.PORT, 'localhost');
- socket.setTimeout(T, function() {
+ var s = socket.setTimeout(T, function() {
socket.destroy();
if (--left === 0) server.close();
assert.ok(killer !== 0);
clearTimeout(timeout);
});
+ assert.ok(s instanceof net.Socket);
socket.setTimeout(killer);
};
var server = tls.Server(options, function(socket) {
- socket.setTimeout(100);
+ var s = socket.setTimeout(100);
+ assert.ok(s instanceof tls.TLSSocket);
socket.on('timeout', function(err) {
hadTimeout = true;
};
var server = tls.createServer(options, function(cleartext) {
- cleartext.setTimeout(50, function() {
+ var s = cleartext.setTimeout(50, function() {
cleartext.destroy();
server.close();
});
+ assert.ok(s instanceof tls.TLSSocket);
});
server.listen(common.PORT, function() {
server.listen(common.PORT, function() {
var socket = net.connect(common.PORT, function() {
- socket.setTimeout(common.platformTimeout(240), function() {
+ var s = socket.setTimeout(common.platformTimeout(240), function() {
throw new Error('timeout');
});
+ assert.ok(s instanceof net.Socket);
var tsocket = tls.connect({
socket: socket,