schnee effeckt und fehler Korektur
This commit is contained in:
55
node_modules/timed-out/index.js
generated
vendored
55
node_modules/timed-out/index.js
generated
vendored
@@ -1,24 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (req, time) {
|
||||
if (req.timeoutTimer) { return req; }
|
||||
if (req.timeoutTimer) {
|
||||
return req;
|
||||
}
|
||||
|
||||
var delays = isNaN(time) ? time : {socket: time, connect: time};
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
// 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.
|
||||
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() {
|
||||
@@ -28,7 +36,20 @@ module.exports = function (req, time) {
|
||||
}
|
||||
}
|
||||
|
||||
return req
|
||||
.on('response', clear)
|
||||
.on('error', clear);
|
||||
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);
|
||||
};
|
||||
|
||||
21
node_modules/timed-out/license
generated
vendored
Normal file
21
node_modules/timed-out/license
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
7
node_modules/timed-out/package.json
generated
vendored
7
node_modules/timed-out/package.json
generated
vendored
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "timed-out",
|
||||
"version": "2.0.0",
|
||||
"version": "4.0.1",
|
||||
"description": "Emit `ETIMEDOUT` or `ESOCKETTIMEDOUT` when ClientRequest is hanged",
|
||||
"license": "MIT",
|
||||
"repository": "floatdrop/timed-out",
|
||||
@@ -12,7 +12,7 @@
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
"test": "xo && mocha"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
@@ -30,6 +30,7 @@
|
||||
"simple"
|
||||
],
|
||||
"devDependencies": {
|
||||
"mocha": "*"
|
||||
"mocha": "*",
|
||||
"xo": "^0.16.0"
|
||||
}
|
||||
}
|
||||
|
||||
9
node_modules/timed-out/readme.md
generated
vendored
9
node_modules/timed-out/readme.md
generated
vendored
@@ -28,9 +28,14 @@ The request to watch on.
|
||||
##### time
|
||||
|
||||
*Required*
|
||||
Type: `number`
|
||||
Type: `number` or `object`
|
||||
|
||||
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.
|
||||
|
||||
Or you can pass Object with following fields:
|
||||
|
||||
- `connect` - time to wait for connection
|
||||
- `socket` - time to wait for activity on socket
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user