Comparing version 2.0.0 to 3.0.0
28
index.js
'use strict'; | ||
module.exports = function (req, time) { | ||
if (req.timeoutTimer) { return req; } | ||
if (req.timeoutTimer) { | ||
return req; | ||
} | ||
@@ -15,9 +17,15 @@ var host = req._headers ? (' to ' + req._headers.host) : ''; | ||
// 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); | ||
// Clear the connection timeout timer once a socket is assigned to the | ||
// request and is connected. Abort the request if there is no activity | ||
// on the socket for more than `time` milliseconds. | ||
req.on('socket', function assign(socket) { | ||
socket.on('connect', function connect() { | ||
clear(); | ||
socket.setTimeout(time, function socketTimeoutHandler() { | ||
req.abort(); | ||
var e = new Error('Socket timed out on request' + host); | ||
e.code = 'ESOCKETTIMEDOUT'; | ||
req.emit('error', e); | ||
}); | ||
}); | ||
}); | ||
@@ -32,5 +40,3 @@ | ||
return req | ||
.on('response', clear) | ||
.on('error', clear); | ||
return req.on('error', clear); | ||
}; |
{ | ||
"name": "timed-out", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Emit `ETIMEDOUT` or `ESOCKETTIMEDOUT` when ClientRequest is hanged", | ||
@@ -15,3 +15,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && mocha" | ||
}, | ||
@@ -34,4 +34,5 @@ "files": [ | ||
"devDependencies": { | ||
"mocha": "*" | ||
"mocha": "*", | ||
"xo": "^0.16.0" | ||
} | ||
} |
@@ -33,3 +33,3 @@ # timed-out [![Build Status](https://travis-ci.org/floatdrop/timed-out.svg?branch=master)](https://travis-ci.org/floatdrop/timed-out) | ||
Time in milliseconds before errors will be emitted and `request.abort()` call happens. | ||
Time in milliseconds to wait for `connect` event on socket and also time to wait on inactive socket. | ||
@@ -36,0 +36,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3580
4
34
2