Beta 7 with some repo names changed.

This commit is contained in:
Luis Fernando Molina committed 2020-11-15 13:05:19 +01:00
1 parent 0f7b40cca7
commit 963c19493a
3408 files changed
+462217 -15516

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
'use strict';
module.exports = function (req, time) {
if (req.timeoutTimer) {
return req;
}
var delays = isNaN(time) ? time : {socket: time, connect: time};
var host = req._headers ? (' to ' + req._headers.host) : '';
if (delays.connect !== undefined) {
req.timeoutTimer = setTimeout(function timeoutHandler() {
req.abort();
var e = new Error('Connection timed out on request' + host);
e.code = 'ETIMEDOUT';
req.emit('error', e);
}, delays.connect);
}
// Clear the connection timeout timer once a socket is assigned to the
// request and is connected.
req.on('socket', function assign(socket) {
// Socket may come from Agent pool and may be already connected.
if (!(socket.connecting || socket._connecting)) {
connect();
return;
}
socket.once('connect', connect);
});
function clear() {
if (req.timeoutTimer) {
clearTimeout(req.timeoutTimer);
req.timeoutTimer = null;
}
}
function connect() {
clear();
if (delays.socket !== undefined) {
// Abort the request if there is no activity on the socket for more
// than `delays.socket` milliseconds.
req.setTimeout(delays.socket, function socketTimeoutHandler() {
req.abort();
var e = new Error('Socket timed out on request' + host);
e.code = 'ESOCKETTIMEDOUT';
req.emit('error', e);
});
}
}
return req.on('error', clear);
};
+40
View File
@@ -0,0 +1,40 @@
{
"name": "timed-out",
"version": "4.0.1",
"description": "Emit `ETIMEDOUT` or `ESOCKETTIMEDOUT` when ClientRequest is hanged",
"license": "MIT",
"repository": "floatdrop/timed-out",
"author": {
"name": "Vsevolod Strukchinsky",
"email": "floatdrop@gmail.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && mocha"
},
"files": [
"index.js"
],
"keywords": [
"http",
"https",
"get",
"got",
"url",
"uri",
"request",
"util",
"utility",
"simple"
],
"devDependencies": {
"mocha": "*",
"xo": "^0.16.0"
}
,"_resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz"
,"_integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8="
,"_from": "timed-out@^4.0.1"
}