@nxtedition/nxt-undici 4.2.10 → 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,6 +8,7 @@ class Handler extends DecoratorHandler {
8
8
  #abort = null
9
9
  #aborted = false
10
10
  #pos = 0
11
+ #created = 0
11
12
  #now = 0
12
13
  #timing = {
13
14
  created: -1,
@@ -15,7 +16,6 @@ class Handler extends DecoratorHandler {
15
16
  headers: -1,
16
17
  data: -1,
17
18
  complete: -1,
18
- error: -1,
19
19
  }
20
20
 
21
21
  constructor(opts, { handler }) {
@@ -25,8 +25,8 @@ class Handler extends DecoratorHandler {
25
25
  this.#opts = opts
26
26
  this.#logger = opts.logger.child({ ureq: { id: opts.id } })
27
27
 
28
- this.#timing.created = performance.now()
29
- this.#now += this.#timing.created
28
+ this.#created = performance.now()
29
+ this.#now += this.#created
30
30
  }
31
31
 
32
32
  onConnect(abort) {
@@ -36,6 +36,10 @@ class Handler extends DecoratorHandler {
36
36
  this.#timing.connect = performance.now() - this.#now
37
37
  this.#now += this.#timing.connect
38
38
 
39
+ this.#timing.headers = -1
40
+ this.#timing.data = -1
41
+ this.#timing.complete = -1
42
+
39
43
  this.#logger.debug({ ureq: this.#opts }, 'upstream request started')
40
44
 
41
45
  return this.#handler.onConnect((reason) => {
@@ -75,15 +79,16 @@ class Handler extends DecoratorHandler {
75
79
  }
76
80
 
77
81
  onComplete(rawTrailers) {
78
- this.#timing.complete = performance.now() - this.#now
79
- this.#now += this.#timing.complete
82
+ this.#timing.complete = performance.now() - this.#created
80
83
 
81
84
  this.#logger.debug(
82
85
  {
86
+ ures: {
87
+ bytesRead: this.#pos,
88
+ bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
89
+ timing: this.#timing,
90
+ },
83
91
  elapsedTime: this.#timing.complete,
84
- bytesRead: this.#pos,
85
- bytesReadPerSecond: (this.#pos * 1e3) / this.#timing.complete,
86
- timing: this.#timing,
87
92
  },
88
93
  'upstream request completed',
89
94
  )
@@ -92,31 +97,23 @@ class Handler extends DecoratorHandler {
92
97
  }
93
98
 
94
99
  onError(err) {
95
- this.#timing.error = performance.now() - this.#now
96
- this.#now += this.#timing.error
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
+ })
97
112
 
98
113
  if (this.#aborted) {
99
- this.#logger.debug(
100
- {
101
- ureq: this.#opts,
102
- bytesRead: this.#pos,
103
- timing: this.#timing,
104
- elapsedTime: this.#timing.error,
105
- err,
106
- },
107
- 'upstream request aborted',
108
- )
114
+ logger.debug('upstream request aborted')
109
115
  } else {
110
- this.#logger.error(
111
- {
112
- ureq: this.#opts,
113
- bytesRead: this.#pos,
114
- timing: this.#timing,
115
- elapsedTime: this.#timing.error,
116
- err,
117
- },
118
- 'upstream request failed',
119
- )
116
+ logger.error('upstream request failed')
120
117
  }
121
118
 
122
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.10",
3
+ "version": "4.2.12",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",