Sha256: b85244367b38e7cb76303fab2496f244bba7a026ddb2c9c3b4e98243b0a88fd3
Contents?: true
Size: 822 Bytes
Versions: 62
Compression:
Stored size: 822 Bytes
Contents
'use strict'; module.exports = function (req, time) { if (req.timeoutTimer) { return req; } var host = req._headers ? (' to ' + req._headers.host) : ''; req.timeoutTimer = setTimeout(function timeoutHandler() { req.abort(); var e = new Error('Connection timed out on request' + host); e.code = 'ETIMEDOUT'; req.emit('error', e); }, time); // Set additional timeout on socket - in case if remote // server freeze after sending headers req.setTimeout(time, function socketTimeoutHandler() { req.abort(); var e = new Error('Socket timed out on request' + host); e.code = 'ESOCKETTIMEDOUT'; req.emit('error', e); }); function clear() { if (req.timeoutTimer) { clearTimeout(req.timeoutTimer); req.timeoutTimer = null; } } return req .on('response', clear) .on('error', clear); };
Version data entries
62 entries across 62 versions & 1 rubygems