@nxtedition/nxt-undici 4.2.9 → 4.2.12

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Matteo Collina and Undici contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -29,6 +29,7 @@ class Handler extends DecoratorHandler {
29
29
  'ENETUNREACH',
30
30
  'EHOSTDOWN',
31
31
  'EHOSTUNREACH',
32
+ 'EHOSTNOTFOUND',
32
33
  'ENODATA',
33
34
  'EPIPE',
34
35
  ].includes(err.code)
@@ -70,7 +71,7 @@ export default (interceptorOpts) => (dispatch) => (opts, handler) => {
70
71
  const url = new URL(opts.origin)
71
72
  url.hostname = Array.isArray(val)
72
73
  ? val[Math.floor(val.length * Math.random())].address
73
- : val?.address ?? val
74
+ : (val?.address ?? val)
74
75
  dispatch(
75
76
  {
76
77
  ...opts,
@@ -8,13 +8,14 @@ class Handler extends DecoratorHandler {
8
8
  #abort = null
9
9
  #aborted = false
10
10
  #pos = 0
11
+ #created = 0
12
+ #now = 0
11
13
  #timing = {
12
- created: performance.now(),
14
+ created: -1,
13
15
  connect: -1,
14
16
  headers: -1,
15
17
  data: -1,
16
18
  complete: -1,
17
- error: -1,
18
19
  }
19
20
 
20
21
  constructor(opts, { handler }) {
@@ -23,12 +24,21 @@ 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.#created = performance.now()
29
+ this.#now += this.#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
38
+
39
+ this.#timing.headers = -1
40
+ this.#timing.data = -1
41
+ this.#timing.complete = -1
32
42
 
33
43
  this.#logger.debug({ ureq: this.#opts }, 'upstream request started')
34
44
 
@@ -48,7 +58,8 @@ class Handler extends DecoratorHandler {
48
58
  }
49
59
 
50
60
  onHeaders(statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
51
- this.#timing.headers = performance.now() - this.#timing.connect - this.#timing.created
61
+ this.#timing.headers = performance.now() - this.#now
62
+ this.#now += this.#timing.headers
52
63
 
53
64
  this.#logger = this.#logger.child({ ures: { statusCode, headers } })
54
65
  this.#logger.debug({ elapsedTime: this.#timing.headers }, 'upstream request response')
@@ -58,7 +69,8 @@ class Handler extends DecoratorHandler {
58
69
 
59
70
  onData(chunk) {
60
71
  if (this.#timing.data === -1) {
61
- this.#timing.data = performance.now() - this.#timing.headers - this.#timing.created
72
+ this.#timing.data = performance.now() - this.#now
73
+ this.#now += this.#timing.data
62
74
  }
63
75
 
64
76
  this.#pos += chunk.length
@@ -67,14 +79,16 @@ class Handler extends DecoratorHandler {
67
79
  }
68
80
 
69
81
  onComplete(rawTrailers) {
70
- this.#timing.complete = performance.now() - this.#timing.data - this.#timing.created
82
+ this.#timing.complete = performance.now() - this.#created
71
83
 
72
84
  this.#logger.debug(
73
85
  {
86
+ ures: {
87
+ bytesRead: this.#pos,
88
+ bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
89
+ timing: this.#timing,
90
+ },
74
91
  elapsedTime: this.#timing.complete,
75
- bytesRead: this.#pos,
76
- bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
77
- timing: this.#timing,
78
92
  },
79
93
  'upstream request completed',
80
94
  )
@@ -83,30 +97,23 @@ class Handler extends DecoratorHandler {
83
97
  }
84
98
 
85
99
  onError(err) {
86
- this.#timing.error = performance.now() - this.#timing.data - this.#timing.created
100
+ this.#timing.complete = performance.now() - this.#created
101
+
102
+ const logger = this.#logger.child({
103
+ ureq: this.#opts,
104
+ ures: {
105
+ bytesRead: this.#pos,
106
+ bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
107
+ timing: this.#timing,
108
+ },
109
+ elapsedTime: this.#timing.complete,
110
+ err,
111
+ })
87
112
 
88
113
  if (this.#aborted) {
89
- this.#logger.debug(
90
- {
91
- ureq: this.#opts,
92
- bytesRead: this.#pos,
93
- timing: this.#timing,
94
- elapsedTime: this.#timing.error,
95
- err,
96
- },
97
- 'upstream request aborted',
98
- )
114
+ logger.debug('upstream request aborted')
99
115
  } else {
100
- this.#logger.error(
101
- {
102
- ureq: this.#opts,
103
- bytesRead: this.#pos,
104
- timing: this.#timing,
105
- elapsedTime: this.#timing.error,
106
- err,
107
- },
108
- 'upstream request failed',
109
- )
116
+ logger.error('upstream request failed')
110
117
  }
111
118
 
112
119
  return this.#handler.onError(err)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "4.2.9",
3
+ "version": "4.2.12",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",