@nxtedition/nxt-undici 4.2.20 → 4.2.22

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.
package/lib/index.js CHANGED
@@ -58,7 +58,7 @@ function wrapDispatcher(dispatcher) {
58
58
  headers,
59
59
  signal: opts.signal,
60
60
  reset: opts.reset ?? false,
61
- blocking: opts.blocking ?? null,
61
+ blocking: opts.blocking ?? opts.method !== 'HEAD',
62
62
  headersTimeout: opts.headersTimeout,
63
63
  bodyTimeout: opts.bodyTimeout,
64
64
  idempotent: opts.idempotent,
@@ -9,13 +9,12 @@ class Handler extends DecoratorHandler {
9
9
  #aborted = false
10
10
  #pos = 0
11
11
  #created = 0
12
- #now = 0
13
12
  #timing = {
14
13
  created: -1,
15
14
  connect: -1,
16
15
  headers: -1,
17
16
  data: -1,
18
- complete: -1,
17
+ end: -1,
19
18
  }
20
19
 
21
20
  constructor(opts, { handler }) {
@@ -26,19 +25,16 @@ class Handler extends DecoratorHandler {
26
25
  this.#logger = opts.logger
27
26
 
28
27
  this.#created = performance.now()
29
- this.#now += this.#created
30
28
  }
31
29
 
32
30
  onConnect(abort) {
33
31
  this.#pos = 0
34
32
  this.#abort = abort
35
33
 
36
- this.#timing.connect = performance.now() - this.#now
37
- this.#now += this.#timing.connect
38
-
34
+ this.#timing.connect = performance.now() - this.#created
39
35
  this.#timing.headers = -1
40
36
  this.#timing.data = -1
41
- this.#timing.complete = -1
37
+ this.#timing.end = -1
42
38
 
43
39
  this.#logger.debug({ ureq: this.#opts }, 'upstream request started')
44
40
 
@@ -58,8 +54,7 @@ class Handler extends DecoratorHandler {
58
54
  }
59
55
 
60
56
  onHeaders(statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
61
- this.#timing.headers = performance.now() - this.#now
62
- this.#now += this.#timing.headers
57
+ this.#timing.headers = performance.now() - this.#created
63
58
 
64
59
  this.#logger.debug(
65
60
  {
@@ -75,8 +70,7 @@ class Handler extends DecoratorHandler {
75
70
 
76
71
  onData(chunk) {
77
72
  if (this.#timing.data === -1) {
78
- this.#timing.data = performance.now() - this.#now
79
- this.#now += this.#timing.data
73
+ this.#timing.data = performance.now() - this.#created
80
74
  }
81
75
 
82
76
  this.#pos += chunk.length
@@ -85,17 +79,17 @@ class Handler extends DecoratorHandler {
85
79
  }
86
80
 
87
81
  onComplete(rawTrailers) {
88
- this.#timing.complete = performance.now() - this.#created
82
+ this.#timing.end = performance.now() - this.#created
89
83
 
90
84
  this.#logger.debug(
91
85
  {
92
86
  ureq: { id: this.#opts.id, url: this.#opts.url },
93
87
  ures: {
94
88
  bytesRead: this.#pos,
95
- bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
89
+ bytesReadPerSecond: (this.#pos * 1e3) / (this.#timing.end - this.#timing.data),
96
90
  timing: this.#timing,
97
91
  },
98
- elapsedTime: this.#timing.complete,
92
+ elapsedTime: this.#timing.end,
99
93
  },
100
94
  'upstream request completed',
101
95
  )
@@ -104,16 +98,16 @@ class Handler extends DecoratorHandler {
104
98
  }
105
99
 
106
100
  onError(err) {
107
- this.#timing.complete = performance.now() - this.#created
101
+ this.#timing.end = performance.now() - this.#created
108
102
 
109
103
  const data = {
110
104
  ureq: this.#opts,
111
105
  ures: {
112
106
  bytesRead: this.#pos,
113
- bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
107
+ bytesReadPerSecond: (this.#pos * 1e3) / (this.#timing.end - this.#timing.data),
114
108
  timing: this.#timing,
115
109
  },
116
- elapsedTime: this.#timing.complete,
110
+ elapsedTime: this.#timing.end,
117
111
  err,
118
112
  }
119
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "4.2.20",
3
+ "version": "4.2.22",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",