aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@szmarczak
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@szmarczak')
-rw-r--r--node_modules/@szmarczak/http-timer/LICENSE21
-rw-r--r--node_modules/@szmarczak/http-timer/README.md93
-rw-r--r--node_modules/@szmarczak/http-timer/dist/source/index.d.ts32
-rw-r--r--node_modules/@szmarczak/http-timer/dist/source/index.js126
-rw-r--r--node_modules/@szmarczak/http-timer/package.json72
5 files changed, 344 insertions, 0 deletions
diff --git a/node_modules/@szmarczak/http-timer/LICENSE b/node_modules/@szmarczak/http-timer/LICENSE
new file mode 100644
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 100644
index 0000000..f58e10b
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/README.md
@@ -0,0 +1,93 @@
+# 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).
+
+## Installation
+
+NPM:
+
+> `npm install @szmarczak/http-timer`
+
+Yarn:
+
+> `yarn add @szmarczak/http-timer`
+
+## Usage
+**Note:**
+> - The measured events resemble Node.js events, not the kernel ones.
+> - Sending a chunk greater than [`highWaterMark`](https://nodejs.org/api/stream.html#stream_new_stream_writable_options) will result in invalid `upload` and `response` timings. You can avoid this by splitting the payload into smaller chunks.
+
+```js
+const https = require('https');
+const timer = require('@szmarczak/http-timer');
+
+const request = https.get('https://httpbin.org/anything');
+timer(request);
+
+request.once('response', response => {
+ response.resume();
+ response.once('end', () => {
+ console.log(response.timings); // You can use `request.timings` as well
+ });
+});
+
+// {
+// start: 1572712180361,
+// socket: 1572712180362,
+// lookup: 1572712180415,
+// connect: 1572712180571,
+// upload: 1572712180884,
+// response: 1572712181037,
+// end: 1572712181039,
+// error: undefined,
+// abort: undefined,
+// phases: {
+// wait: 1,
+// dns: 53,
+// tcp: 156,
+// request: 313,
+// firstByte: 153,
+// download: 2,
+// total: 678
+// }
+// }
+```
+
+## API
+
+### timer(request)
+
+Returns: `Object`
+
+**Note**: The time is a `number` representing the milliseconds elapsed since the UNIX epoch.
+
+- `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.
+- `secureConnect` - Time when the socket securely connected.
+- `upload` - Time when the request finished uploading.
+- `response` - Time when the request fired `response` event.
+- `end` - Time when the response fired `end` event.
+- `error` - Time when the request fired `error` event.
+- `abort` - Time when the request fired `abort` event.
+- `phases`
+ - `wait` - `timings.socket - timings.start`
+ - `dns` - `timings.lookup - timings.socket`
+ - `tcp` - `timings.connect - timings.lookup`
+ - `tls` - `timings.secureConnect - timings.connect`
+ - `request` - `timings.upload - (timings.secureConnect || timings.connect)`
+ - `firstByte` - `timings.response - timings.upload`
+ - `download` - `timings.end - timings.response`
+ - `total` - `(timings.end || timings.error || timings.abort) - timings.start`
+
+If something has not been measured yet, it will be `undefined`.
+
+## License
+
+MIT
diff --git a/node_modules/@szmarczak/http-timer/dist/source/index.d.ts b/node_modules/@szmarczak/http-timer/dist/source/index.d.ts
new file mode 100644
index 0000000..2620b4a
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/dist/source/index.d.ts
@@ -0,0 +1,32 @@
+/// <reference types="node" />
+import { ClientRequest, IncomingMessage } from 'http';
+export interface Timings {
+ start: number;
+ socket?: number;
+ lookup?: number;
+ connect?: number;
+ secureConnect?: number;
+ upload?: number;
+ response?: number;
+ end?: number;
+ error?: number;
+ abort?: number;
+ phases: {
+ wait?: number;
+ dns?: number;
+ tcp?: number;
+ tls?: number;
+ request?: number;
+ firstByte?: number;
+ download?: number;
+ total?: number;
+ };
+}
+export interface ClientRequestWithTimings extends ClientRequest {
+ timings?: Timings;
+}
+export interface IncomingMessageWithTimings extends IncomingMessage {
+ timings?: Timings;
+}
+declare const timer: (request: ClientRequestWithTimings) => Timings;
+export default timer;
diff --git a/node_modules/@szmarczak/http-timer/dist/source/index.js b/node_modules/@szmarczak/http-timer/dist/source/index.js
new file mode 100644
index 0000000..6f07245
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/dist/source/index.js
@@ -0,0 +1,126 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+const defer_to_connect_1 = require("defer-to-connect");
+const util_1 = require("util");
+const nodejsMajorVersion = Number(process.versions.node.split('.')[0]);
+const timer = (request) => {
+ if (request.timings) {
+ return request.timings;
+ }
+ const timings = {
+ start: Date.now(),
+ socket: undefined,
+ lookup: undefined,
+ connect: undefined,
+ secureConnect: undefined,
+ upload: undefined,
+ response: undefined,
+ end: undefined,
+ error: undefined,
+ abort: undefined,
+ phases: {
+ wait: undefined,
+ dns: undefined,
+ tcp: undefined,
+ tls: undefined,
+ request: undefined,
+ firstByte: undefined,
+ download: undefined,
+ total: undefined
+ }
+ };
+ request.timings = timings;
+ 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);
+ };
+ };
+ handleError(request);
+ const onAbort = () => {
+ timings.abort = Date.now();
+ // Let the `end` response event be responsible for setting the total phase,
+ // unless the Node.js major version is >= 13.
+ if (!timings.response || nodejsMajorVersion >= 13) {
+ timings.phases.total = Date.now() - timings.start;
+ }
+ };
+ request.prependOnceListener('abort', onAbort);
+ const onSocket = (socket) => {
+ timings.socket = Date.now();
+ timings.phases.wait = timings.socket - timings.start;
+ if (util_1.types.isProxy(socket)) {
+ return;
+ }
+ const lookupListener = () => {
+ timings.lookup = Date.now();
+ timings.phases.dns = timings.lookup - timings.socket;
+ };
+ socket.prependOnceListener('lookup', lookupListener);
+ defer_to_connect_1.default(socket, {
+ connect: () => {
+ timings.connect = Date.now();
+ if (timings.lookup === undefined) {
+ socket.removeListener('lookup', lookupListener);
+ timings.lookup = timings.connect;
+ timings.phases.dns = timings.lookup - timings.socket;
+ }
+ timings.phases.tcp = timings.connect - timings.lookup;
+ // This callback is called before flushing any data,
+ // so we don't need to set `timings.phases.request` here.
+ },
+ secureConnect: () => {
+ timings.secureConnect = Date.now();
+ timings.phases.tls = timings.secureConnect - timings.connect;
+ }
+ });
+ };
+ if (request.socket) {
+ onSocket(request.socket);
+ }
+ else {
+ request.prependOnceListener('socket', onSocket);
+ }
+ const onUpload = () => {
+ var _a;
+ timings.upload = Date.now();
+ timings.phases.request = timings.upload - ((_a = timings.secureConnect) !== null && _a !== void 0 ? _a : timings.connect);
+ };
+ const writableFinished = () => {
+ if (typeof request.writableFinished === 'boolean') {
+ return request.writableFinished;
+ }
+ // Node.js doesn't have `request.writableFinished` property
+ return request.finished && request.outputSize === 0 && (!request.socket || request.socket.writableLength === 0);
+ };
+ if (writableFinished()) {
+ onUpload();
+ }
+ else {
+ request.prependOnceListener('finish', onUpload);
+ }
+ request.prependOnceListener('response', (response) => {
+ timings.response = Date.now();
+ timings.phases.firstByte = timings.response - timings.upload;
+ response.timings = timings;
+ handleError(response);
+ response.prependOnceListener('end', () => {
+ timings.end = Date.now();
+ timings.phases.download = timings.end - timings.response;
+ timings.phases.total = timings.end - timings.start;
+ });
+ response.prependOnceListener('aborted', onAbort);
+ });
+ return timings;
+};
+exports.default = timer;
+// For CommonJS default export support
+module.exports = timer;
+module.exports.default = timer;
diff --git a/node_modules/@szmarczak/http-timer/package.json b/node_modules/@szmarczak/http-timer/package.json
new file mode 100644
index 0000000..43a3559
--- /dev/null
+++ b/node_modules/@szmarczak/http-timer/package.json
@@ -0,0 +1,72 @@
+{
+ "name": "@szmarczak/http-timer",
+ "version": "4.0.6",
+ "description": "Timings for HTTP requests",
+ "main": "dist/source",
+ "engines": {
+ "node": ">=10"
+ },
+ "scripts": {
+ "test": "xo && tsc --noEmit && nyc ava",
+ "build": "del-cli dist && tsc",
+ "prepare": "npm run build",
+ "coveralls": "nyc report --reporter=text-lcov | coveralls"
+ },
+ "files": [
+ "dist/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",
+ "dependencies": {
+ "defer-to-connect": "^2.0.0"
+ },
+ "devDependencies": {
+ "@ava/typescript": "^2.0.0",
+ "@sindresorhus/tsconfig": "^1.0.2",
+ "@types/node": "^16.3.1",
+ "ava": "^3.15.0",
+ "coveralls": "^3.1.1",
+ "del-cli": "^3.0.1",
+ "http2-wrapper": "^2.0.7",
+ "nyc": "^15.1.0",
+ "p-event": "^4.2.0",
+ "typescript": "^4.3.5",
+ "xo": "^0.39.1"
+ },
+ "types": "dist/source",
+ "nyc": {
+ "extension": [
+ ".ts"
+ ],
+ "exclude": [
+ "**/tests/**"
+ ]
+ },
+ "xo": {
+ "rules": {
+ "@typescript-eslint/no-non-null-assertion": "off"
+ }
+ },
+ "ava": {
+ "typescript": {
+ "compile": false,
+ "rewritePaths": {
+ "tests/": "dist/tests/"
+ }
+ }
+ }
+}