@nxtedition/nxt-undici 5.1.8 → 5.2.0

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.
@@ -9,7 +9,6 @@ import {
9
9
 
10
10
  // TODO (fix): What about onUpgrade?
11
11
  class Handler extends DecoratorHandler {
12
- #handler
13
12
  #dispatch
14
13
  #opts
15
14
 
@@ -29,7 +28,6 @@ class Handler extends DecoratorHandler {
29
28
  constructor(opts, { handler, dispatch }) {
30
29
  super(handler)
31
30
 
32
- this.#handler = handler
33
31
  this.#dispatch = dispatch
34
32
 
35
33
  if (typeof opts === 'number') {
@@ -50,7 +48,7 @@ class Handler extends DecoratorHandler {
50
48
  this.#etag = null
51
49
  this.#error = null
52
50
 
53
- this.#handler.onConnect((reason) => {
51
+ super.onConnect((reason) => {
54
52
  if (!this.#aborted) {
55
53
  this.#aborted = true
56
54
  if (this.#abort) {
@@ -149,7 +147,7 @@ class Handler extends DecoratorHandler {
149
147
  if (this.#pos != null) {
150
148
  this.#pos += chunk.byteLength
151
149
  }
152
- return this.#handler.onData(chunk)
150
+ return super.onData(chunk)
153
151
  }
154
152
 
155
153
  onError(err) {
@@ -158,7 +156,13 @@ class Handler extends DecoratorHandler {
158
156
  return
159
157
  }
160
158
 
161
- const retryPromise = retryFn(err, this.#retryCount, { ...this.#opts.retry })
159
+ let retryPromise
160
+ try {
161
+ retryPromise = retryFn(err, this.#retryCount, { ...this.#opts.retry })
162
+ } catch (err) {
163
+ retryPromise = Promise.reject(err)
164
+ }
165
+
162
166
  if (retryPromise == null) {
163
167
  this.#onError(err)
164
168
  return
@@ -206,13 +210,13 @@ class Handler extends DecoratorHandler {
206
210
  #onError(err) {
207
211
  assert(!this.#errorSent)
208
212
  this.#errorSent = true
209
- this.#handler.onError(err)
213
+ super.onError(err)
210
214
  }
211
215
 
212
216
  #onHeaders(...args) {
213
217
  assert(!this.#headersSent)
214
218
  this.#headersSent = true
215
- return this.#handler.onHeaders(...args)
219
+ return super.onHeaders(...args)
216
220
  }
217
221
  }
218
222
 
@@ -2,24 +2,17 @@ import crypto from 'node:crypto'
2
2
  import assert from 'node:assert'
3
3
  import { DecoratorHandler, parseHeaders } from '../utils.js'
4
4
 
5
- const DEFAULT_OPTS = { hash: null }
6
-
7
5
  class Handler extends DecoratorHandler {
8
- #handler
9
-
10
6
  #verifyOpts
11
7
  #contentMD5
12
8
  #contentLength
13
9
  #hasher
14
10
  #pos = 0
15
- #errorSent = false
16
11
 
17
12
  constructor(opts, { handler }) {
18
13
  super(handler)
19
14
 
20
- this.#handler = handler
21
- this.#verifyOpts =
22
- opts.verify === true ? { hash: true, size: true } : (opts.verify ?? DEFAULT_OPTS)
15
+ this.#verifyOpts = opts.verify === true ? { hash: true, size: true } : opts.verify
23
16
  }
24
17
 
25
18
  onConnect(abort) {
@@ -29,54 +22,44 @@ class Handler extends DecoratorHandler {
29
22
  this.#contentLength = null
30
23
  this.#hasher = null
31
24
  this.#pos = 0
32
- this.#errorSent = false
33
25
 
34
- this.#handler.onConnect(abort)
26
+ super.onConnect(abort)
35
27
  }
36
28
 
37
29
  onHeaders(statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
38
30
  this.#contentMD5 = this.#verifyOpts.hash ? headers['content-md5'] : null
39
- this.#contentLength = this.#verifyOpts.hash ? headers['content-length'] : null
31
+ this.#contentLength = this.#verifyOpts.size ? headers['content-length'] : null
40
32
  this.#hasher = this.#contentMD5 != null ? crypto.createHash('md5') : null
41
33
 
42
- return this.#handler.onHeaders(statusCode, null, resume, null, headers)
34
+ return super.onHeaders(statusCode, null, resume, null, headers)
43
35
  }
44
36
 
45
37
  onData(chunk) {
46
38
  this.#pos += chunk.length
47
39
  this.#hasher?.update(chunk)
48
40
 
49
- return this.#handler.onData(chunk)
41
+ return super.onData(chunk)
50
42
  }
51
43
 
52
44
  onComplete() {
53
45
  const contentMD5 = this.#hasher?.digest('base64')
54
46
 
55
47
  if (this.#contentLength != null && this.#pos !== Number(this.#contentLength)) {
56
- this.#errorSent = true
57
- this.#handler.onError(
48
+ super.onError(
58
49
  Object.assign(new Error('Request Content-Length mismatch'), {
59
50
  expected: Number(this.#contentLength),
60
51
  actual: this.#pos,
61
52
  }),
62
53
  )
63
54
  } else if (this.#contentMD5 != null && contentMD5 !== this.#contentMD5) {
64
- this.#errorSent = true
65
- this.#handler.onError(
55
+ super.onError(
66
56
  Object.assign(new Error('Request Content-MD5 mismatch'), {
67
57
  expected: this.#contentMD5,
68
58
  actual: contentMD5,
69
59
  }),
70
60
  )
71
61
  } else {
72
- return this.#handler.onComplete()
73
- }
74
- }
75
-
76
- onError(err) {
77
- if (!this.#errorSent) {
78
- this.#errorSent = true
79
- this.#handler.onError(err)
62
+ super.onComplete()
80
63
  }
81
64
  }
82
65
  }
package/lib/request.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import assert from 'node:assert'
2
2
  import { InvalidArgumentError, RequestAbortedError } from './errors.js'
3
3
  import { isStream, parseHeaders } from './utils.js'
4
- import { BodyReadable as Readable } from './readable.js'
4
+ import { Readable } from '@nxtedition/undici'
5
5
 
6
6
  function noop() {}
7
7
 
package/lib/utils.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import tp from 'node:timers/promises'
2
2
  import cacheControlParser from 'cache-control-parser'
3
3
  import stream from 'node:stream'
4
- import { util } from 'undici'
4
+ import { util } from '@nxtedition/undici'
5
5
 
6
6
  let fastNow = Date.now()
7
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "5.1.8",
3
+ "version": "5.2.0",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",
@@ -9,17 +9,16 @@
9
9
  "lib/*"
10
10
  ],
11
11
  "dependencies": {
12
+ "@nxtedition/undici": "^9.0.3",
12
13
  "cache-control-parser": "^2.0.6",
13
- "http-errors": "^2.0.0",
14
- "lru-cache": "^11.0.2",
15
- "undici": "^6.0.0"
14
+ "http-errors": "^2.0.0"
16
15
  },
17
16
  "devDependencies": {
18
- "@types/node": "^22.10.1",
17
+ "@types/node": "^22.10.7",
19
18
  "eslint": "^9.16.0",
20
19
  "eslint-plugin-n": "^17.14.0",
21
20
  "husky": "^9.1.7",
22
- "lint-staged": "^15.2.10",
21
+ "lint-staged": "^15.4.1",
23
22
  "pinst": "^3.0.0",
24
23
  "prettier": "^3.4.1",
25
24
  "send": "^1.1.0",