aboutsummaryrefslogtreecommitdiff
path: root/node_modules/timed-out
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-28 00:38:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-28 00:40:43 +0200
commit7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch)
tree6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/timed-out
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
downloadwallet-core-7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027.tar.xz
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/timed-out')
-rw-r--r--node_modules/timed-out/index.js55
-rw-r--r--node_modules/timed-out/license21
-rw-r--r--node_modules/timed-out/package.json36
-rw-r--r--node_modules/timed-out/readme.md42
4 files changed, 154 insertions, 0 deletions
diff --git a/node_modules/timed-out/index.js b/node_modules/timed-out/index.js
new file mode 100644
index 000000000..94007a4ae
--- /dev/null
+++ b/node_modules/timed-out/index.js
@@ -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);
+};
diff --git a/node_modules/timed-out/license b/node_modules/timed-out/license
new file mode 100644
index 000000000..faadd5287
--- /dev/null
+++ b/node_modules/timed-out/license
@@ -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.
diff --git a/node_modules/timed-out/package.json b/node_modules/timed-out/package.json
new file mode 100644
index 000000000..b86baa703
--- /dev/null
+++ b/node_modules/timed-out/package.json
@@ -0,0 +1,36 @@
+{
+ "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"
+ }
+}
diff --git a/node_modules/timed-out/readme.md b/node_modules/timed-out/readme.md
new file mode 100644
index 000000000..fa0a03565
--- /dev/null
+++ b/node_modules/timed-out/readme.md
@@ -0,0 +1,42 @@
+# timed-out [![Build Status](https://travis-ci.org/floatdrop/timed-out.svg?branch=master)](https://travis-ci.org/floatdrop/timed-out)
+
+> Timeout HTTP/HTTPS requests
+
+Emit Error object with `code` property equal `ETIMEDOUT` or `ESOCKETTIMEDOUT` when ClientRequest is hanged.
+
+## Usage
+
+```js
+var get = require('http').get;
+var timeout = require('timed-out');
+
+var req = get('http://www.google.ru');
+timeout(req, 2000); // Set 2 seconds limit
+```
+
+### API
+
+#### timedout(request, time)
+
+##### request
+
+*Required*
+Type: [`ClientRequest`](http://nodejs.org/api/http.html#http_class_http_clientrequest)
+
+The request to watch on.
+
+##### time
+
+*Required*
+Type: `number` or `object`
+
+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
+
+MIT © [Vsevolod Strukchinsky](floatdrop@gmail.com)