summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/@szmarczak/http-timer/dist
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
committerRaindropsSys <contact@minteck.org>2023-04-06 22:18:28 +0200
commit83354b2b88218090988dd6e526b0a2505b57e0f1 (patch)
treee3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/node_modules/@szmarczak/http-timer/dist
parent47b8f2299a483024c4a6a8876af825a010954caa (diff)
downloadpluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2
pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/@szmarczak/http-timer/dist')
-rw-r--r--includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.d.ts32
-rw-r--r--includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.js106
2 files changed, 138 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.d.ts b/includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.d.ts
new file mode 100644
index 0000000..cae5c24
--- /dev/null
+++ b/includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.d.ts
@@ -0,0 +1,32 @@
+/// <reference types="node" />
+import type { 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/includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.js b/includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.js
new file mode 100644
index 0000000..407014f
--- /dev/null
+++ b/includes/external/addressbook/node_modules/@szmarczak/http-timer/dist/source/index.js
@@ -0,0 +1,106 @@
+import { errorMonitor } from 'events';
+import { types } from 'util';
+import deferToConnect from 'defer-to-connect';
+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) => {
+ origin.once(errorMonitor, () => {
+ timings.error = Date.now();
+ timings.phases.total = timings.error - timings.start;
+ });
+ };
+ handleError(request);
+ const onAbort = () => {
+ timings.abort = Date.now();
+ timings.phases.total = timings.abort - timings.start;
+ };
+ request.prependOnceListener('abort', onAbort);
+ const onSocket = (socket) => {
+ timings.socket = Date.now();
+ timings.phases.wait = timings.socket - timings.start;
+ if (types.isProxy(socket)) {
+ return;
+ }
+ const lookupListener = () => {
+ timings.lookup = Date.now();
+ timings.phases.dns = timings.lookup - timings.socket;
+ };
+ socket.prependOnceListener('lookup', lookupListener);
+ deferToConnect(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;
+ },
+ 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 = () => {
+ timings.upload = Date.now();
+ timings.phases.request = timings.upload - (timings.secureConnect ?? timings.connect);
+ };
+ if (request.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', () => {
+ request.off('abort', onAbort);
+ response.off('aborted', onAbort);
+ if (timings.phases.total) {
+ // Aborted or errored
+ return;
+ }
+ timings.end = Date.now();
+ timings.phases.download = timings.end - timings.response;
+ timings.phases.total = timings.end - timings.start;
+ });
+ response.prependOnceListener('aborted', onAbort);
+ });
+ return timings;
+};
+export default timer;