@nxtedition/nxt-undici 4.2.8 → 4.2.10

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.
@@ -8,8 +8,9 @@ class Handler extends DecoratorHandler {
8
8
  #abort = null
9
9
  #aborted = false
10
10
  #pos = 0
11
+ #now = 0
11
12
  #timing = {
12
- created: performance.now(),
13
+ created: -1,
13
14
  connect: -1,
14
15
  headers: -1,
15
16
  data: -1,
@@ -23,12 +24,17 @@ class Handler extends DecoratorHandler {
23
24
  this.#handler = handler
24
25
  this.#opts = opts
25
26
  this.#logger = opts.logger.child({ ureq: { id: opts.id } })
27
+
28
+ this.#timing.created = performance.now()
29
+ this.#now += this.#timing.created
26
30
  }
27
31
 
28
32
  onConnect(abort) {
29
33
  this.#pos = 0
30
34
  this.#abort = abort
31
- this.#timing.connect = performance.now() - this.#timing.created
35
+
36
+ this.#timing.connect = performance.now() - this.#now
37
+ this.#now += this.#timing.connect
32
38
 
33
39
  this.#logger.debug({ ureq: this.#opts }, 'upstream request started')
34
40
 
@@ -48,22 +54,19 @@ class Handler extends DecoratorHandler {
48
54
  }
49
55
 
50
56
  onHeaders(statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
51
- this.#timing.headers = performance.now() - this.#timing.connect - this.#timing.created
57
+ this.#timing.headers = performance.now() - this.#now
58
+ this.#now += this.#timing.headers
52
59
 
53
- this.#logger.debug(
54
- {
55
- ures: { statusCode, headers },
56
- elapsedTime: this.#timing.headers,
57
- },
58
- 'upstream request response',
59
- )
60
+ this.#logger = this.#logger.child({ ures: { statusCode, headers } })
61
+ this.#logger.debug({ elapsedTime: this.#timing.headers }, 'upstream request response')
60
62
 
61
63
  return this.#handler.onHeaders(statusCode, rawHeaders, resume, statusMessage, headers)
62
64
  }
63
65
 
64
66
  onData(chunk) {
65
67
  if (this.#timing.data === -1) {
66
- this.#timing.data = performance.now() - this.#timing.headers - this.#timing.created
68
+ this.#timing.data = performance.now() - this.#now
69
+ this.#now += this.#timing.data
67
70
  }
68
71
 
69
72
  this.#pos += chunk.length
@@ -72,10 +75,16 @@ class Handler extends DecoratorHandler {
72
75
  }
73
76
 
74
77
  onComplete(rawTrailers) {
75
- this.#timing.complete = performance.now() - this.#timing.data - this.#timing.created
78
+ this.#timing.complete = performance.now() - this.#now
79
+ this.#now += this.#timing.complete
76
80
 
77
81
  this.#logger.debug(
78
- { elapsedTime: this.#timing.complete, bytesRead: this.#pos, timing: this.#timing },
82
+ {
83
+ elapsedTime: this.#timing.complete,
84
+ bytesRead: this.#pos,
85
+ bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
86
+ timing: this.#timing,
87
+ },
79
88
  'upstream request completed',
80
89
  )
81
90
 
@@ -83,7 +92,8 @@ class Handler extends DecoratorHandler {
83
92
  }
84
93
 
85
94
  onError(err) {
86
- this.#timing.error = performance.now() - this.#timing.data - this.#timing.created
95
+ this.#timing.error = performance.now() - this.#now
96
+ this.#now += this.#timing.error
87
97
 
88
98
  if (this.#aborted) {
89
99
  this.#logger.debug(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "4.2.8",
3
+ "version": "4.2.10",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",