@nxtedition/nxt-undici 3.3.1 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,8 +7,14 @@ class Handler extends DecoratorHandler {
7
7
  #aborted = false
8
8
  #logger
9
9
  #pos
10
- #timing
11
- #startTime = performance.now()
10
+ #timing = {
11
+ created: performance.now(),
12
+ connect: -1,
13
+ headers: -1,
14
+ data: -1,
15
+ complete: -1,
16
+ error: -1,
17
+ }
12
18
 
13
19
  constructor(opts, { handler }) {
14
20
  super(handler)
@@ -21,13 +27,7 @@ class Handler extends DecoratorHandler {
21
27
  onConnect(abort) {
22
28
  this.#pos = 0
23
29
  this.#abort = abort
24
- this.#timing = {
25
- connect: performance.now() - this.#startTime,
26
- headers: -1,
27
- data: -1,
28
- complete: -1,
29
- error: -1,
30
- }
30
+ this.#timing.connect = performance.now() - this.#timing.created
31
31
 
32
32
  this.#logger.debug({ ureq: this.#opts }, 'upstream request started')
33
33
 
@@ -47,7 +47,7 @@ class Handler extends DecoratorHandler {
47
47
  }
48
48
 
49
49
  onHeaders(statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
50
- this.#timing.headers = performance.now() - this.#timing.connect - this.#startTime
50
+ this.#timing.headers = performance.now() - this.#timing.connect - this.#timing.created
51
51
 
52
52
  this.#logger.debug(
53
53
  {
@@ -62,7 +62,7 @@ class Handler extends DecoratorHandler {
62
62
 
63
63
  onData(chunk) {
64
64
  if (this.#timing.data === -1) {
65
- this.#timing.data = performance.now() - this.#timing.headers - this.#startTime
65
+ this.#timing.data = performance.now() - this.#timing.headers - this.#timing.created
66
66
  }
67
67
 
68
68
  this.#pos += chunk.length
@@ -71,7 +71,7 @@ class Handler extends DecoratorHandler {
71
71
  }
72
72
 
73
73
  onComplete(rawTrailers) {
74
- this.#timing.complete = performance.now() - this.#timing.data - this.#startTime
74
+ this.#timing.complete = performance.now() - this.#timing.data - this.#timing.created
75
75
 
76
76
  this.#logger.debug(
77
77
  { elapsedTime: this.#timing.complete, bytesRead: this.#pos, timing: this.#timing },
@@ -82,7 +82,7 @@ class Handler extends DecoratorHandler {
82
82
  }
83
83
 
84
84
  onError(err) {
85
- this.#timing.error = performance.now() - this.#timing.data - this.#startTime
85
+ this.#timing.error = performance.now() - this.#timing.data - this.#timing.created
86
86
 
87
87
  if (this.#aborted) {
88
88
  this.#logger.debug(
package/lib/utils.js CHANGED
@@ -250,6 +250,7 @@ export function bodyLength(body) {
250
250
 
251
251
  export class DecoratorHandler {
252
252
  #handler
253
+ #onConnectCalled = false
253
254
 
254
255
  constructor(handler) {
255
256
  if (typeof handler !== 'object' || handler === null) {
@@ -259,10 +260,15 @@ export class DecoratorHandler {
259
260
  }
260
261
 
261
262
  onConnect(...args) {
263
+ this.#onConnectCalled = true
262
264
  return this.#handler.onConnect?.(...args)
263
265
  }
264
266
 
265
267
  onError(...args) {
268
+ if (!this.#onConnectCalled) {
269
+ this.#onConnectCalled = true
270
+ this.#handler.onConnect?.(...args)
271
+ }
266
272
  return this.#handler.onError?.(...args)
267
273
  }
268
274
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "3.3.1",
3
+ "version": "3.3.2",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",