aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@szmarczak
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-04-09 16:39:03 +0200
committerMinteck <contact@minteck.org>2022-04-09 16:40:02 +0200
commit0f8967b9113d698cdeb2d05ca85d2d9a80461c24 (patch)
tree00664ddd9c55a2c33631fd1bd33e556cea9c67e5 /node_modules/@szmarczak
parentdac03ac82bc0f8044a4b339c27b5390e4dcecf2f (diff)
downloadvoicer-0f8967b9113d698cdeb2d05ca85d2d9a80461c24.tar.gz
voicer-0f8967b9113d698cdeb2d05ca85d2d9a80461c24.tar.bz2
voicer-0f8967b9113d698cdeb2d05ca85d2d9a80461c24.zip
CommitHEADtrunk
Diffstat (limited to 'node_modules/@szmarczak')
-rwxr-xr-xnode_modules/@szmarczak/http-timer/LICENSE21
-rwxr-xr-xnode_modules/@szmarczak/http-timer/README.md70
-rwxr-xr-xnode_modules/@szmarczak/http-timer/package.json47
-rwxr-xr-xnode_modules/@szmarczak/http-timer/source/index.js99
4 files changed, 237 insertions, 0 deletions
diff --git a/node_modules/@szmarczak/http-timer/LICENSE b/node_modules/@szmarczak/http-timer/LICENSE
new file mode 100755
index 0000000..15ad2e8
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2018 Szymon Marczak
+
+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/@szmarczak/http-timer/README.md b/node_modules/@szmarczak/http-timer/README.md
new file mode 100755
index 0000000..13279ed
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/README.md
@@ -0,0 +1,70 @@
+# http-timer
+> Timings for HTTP requests
+
+[![Build Status](https://travis-ci.org/szmarczak/http-timer.svg?branch=master)](https://travis-ci.org/szmarczak/http-timer)
+[![Coverage Status](https://coveralls.io/repos/github/szmarczak/http-timer/badge.svg?branch=master)](https://coveralls.io/github/szmarczak/http-timer?branch=master)
+[![install size](https://packagephobia.now.sh/badge?p=@szmarczak/http-timer)](https://packagephobia.now.sh/result?p=@szmarczak/http-timer)
+
+Inspired by the [`request` package](https://github.com/request/request).
+
+## Usage
+```js
+'use strict';
+const https = require('https');
+const timer = require('@szmarczak/http-timer');
+
+const request = https.get('https://httpbin.org/anything');
+const timings = timer(request);
+
+request.on('response', response => {
+ response.on('data', () => {}); // Consume the data somehow
+ response.on('end', () => {
+ console.log(timings);
+ });
+});
+
+// { start: 1535708511443,
+// socket: 1535708511444,
+// lookup: 1535708511444,
+// connect: 1535708511582,
+// upload: 1535708511887,
+// response: 1535708512037,
+// end: 1535708512040,
+// phases:
+// { wait: 1,
+// dns: 0,
+// tcp: 138,
+// request: 305,
+// firstByte: 150,
+// download: 3,
+// total: 597 } }
+```
+
+## API
+
+### timer(request)
+
+Returns: `Object`
+
+- `start` - Time when the request started.
+- `socket` - Time when a socket was assigned to the request.
+- `lookup` - Time when the DNS lookup finished.
+- `connect` - Time when the socket successfully connected.
+- `upload` - Time when the request finished uploading.
+- `response` - Time when the request fired the `response` event.
+- `end` - Time when the response fired the `end` event.
+- `error` - Time when the request fired the `error` event.
+- `phases`
+ - `wait` - `timings.socket - timings.start`
+ - `dns` - `timings.lookup - timings.socket`
+ - `tcp` - `timings.connect - timings.lookup`
+ - `request` - `timings.upload - timings.connect`
+ - `firstByte` - `timings.response - timings.upload`
+ - `download` - `timings.end - timings.response`
+ - `total` - `timings.end - timings.start` or `timings.error - timings.start`
+
+**Note**: The time is a `number` representing the milliseconds elapsed since the UNIX epoch.
+
+## License
+
+MIT
diff --git a/node_modules/@szmarczak/http-timer/package.json b/node_modules/@szmarczak/http-timer/package.json
new file mode 100755
index 0000000..9346648
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/package.json
@@ -0,0 +1,47 @@
+{
+ "name": "@szmarczak/http-timer",
+ "version": "1.1.2",
+ "description": "Timings for HTTP requests",
+ "main": "source",
+ "engines": {
+ "node": ">=6"
+ },
+ "scripts": {
+ "test": "xo && nyc ava",
+ "coveralls": "nyc report --reporter=text-lcov | coveralls"
+ },
+ "files": [
+ "source"
+ ],
+ "keywords": [
+ "http",
+ "https",
+ "timer",
+ "timings"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/szmarczak/http-timer.git"
+ },
+ "author": "Szymon Marczak",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/szmarczak/http-timer/issues"
+ },
+ "homepage": "https://github.com/szmarczak/http-timer#readme",
+ "xo": {
+ "rules": {
+ "unicorn/filename-case": "camelCase"
+ }
+ },
+ "devDependencies": {
+ "ava": "^0.25.0",
+ "coveralls": "^3.0.2",
+ "p-event": "^2.1.0",
+ "nyc": "^12.0.2",
+ "xo": "^0.22.0"
+ },
+ "dependencies": {
+ "defer-to-connect": "^1.0.1"
+ }
+}
diff --git a/node_modules/@szmarczak/http-timer/source/index.js b/node_modules/@szmarczak/http-timer/source/index.js
new file mode 100755
index 0000000..e294580
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/source/index.js
@@ -0,0 +1,99 @@
+'use strict';
+const deferToConnect = require('defer-to-connect');
+
+module.exports = request => {
+ const timings = {
+ start: Date.now(),
+ socket: null,
+ lookup: null,
+ connect: null,
+ upload: null,
+ response: null,
+ end: null,
+ error: null,
+ phases: {
+ wait: null,
+ dns: null,
+ tcp: null,
+ request: null,
+ firstByte: null,
+ download: null,
+ total: null
+ }
+ };
+
+ const handleError = origin => {
+ const emit = origin.emit.bind(origin);
+ origin.emit = (event, ...args) => {
+ // Catches the `error` event
+ if (event === 'error') {
+ timings.error = Date.now();
+ timings.phases.total = timings.error - timings.start;
+
+ origin.emit = emit;
+ }
+
+ // Saves the original behavior
+ return emit(event, ...args);
+ };
+ };
+
+ let uploadFinished = false;
+ const onUpload = () => {
+ timings.upload = Date.now();
+ timings.phases.request = timings.upload - timings.connect;
+ };
+
+ handleError(request);
+
+ request.once('socket', socket => {
+ timings.socket = Date.now();
+ timings.phases.wait = timings.socket - timings.start;
+
+ const lookupListener = () => {
+ timings.lookup = Date.now();
+ timings.phases.dns = timings.lookup - timings.socket;
+ };
+
+ socket.once('lookup', lookupListener);
+
+ deferToConnect(socket, () => {
+ timings.connect = Date.now();
+
+ if (timings.lookup === null) {
+ socket.removeListener('lookup', lookupListener);
+ timings.lookup = timings.connect;
+ timings.phases.dns = timings.lookup - timings.socket;
+ }
+
+ timings.phases.tcp = timings.connect - timings.lookup;
+
+ if (uploadFinished && !timings.upload) {
+ onUpload();
+ }
+ });
+ });
+
+ request.once('finish', () => {
+ uploadFinished = true;
+
+ if (timings.connect) {
+ onUpload();
+ }
+ });
+
+ request.once('response', response => {
+ timings.response = Date.now();
+ timings.phases.firstByte = timings.response - timings.upload;
+
+ handleError(response);
+
+ response.once('end', () => {
+ timings.end = Date.now();
+ timings.phases.download = timings.end - timings.response;
+ timings.phases.total = timings.end - timings.start;
+ });
+ });
+
+ return timings;
+};