@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.
- package/lib/cache/sqlite-cache-store.js +439 -0
- package/lib/cache/util.js +51 -0
- package/lib/index.js +10 -7
- package/lib/interceptor/cache.js +100 -119
- package/lib/interceptor/dns.js +19 -36
- package/lib/interceptor/log.js +6 -8
- package/lib/interceptor/proxy.js +2 -4
- package/lib/interceptor/redirect.js +9 -11
- package/lib/interceptor/response-error.js +19 -27
- package/lib/interceptor/response-retry.js +11 -7
- package/lib/interceptor/response-verify.js +8 -25
- package/lib/request.js +1 -1
- package/lib/utils.js +1 -1
- package/package.json +5 -6
- package/lib/readable.js +0 -523
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
213
|
+
super.onError(err)
|
|
210
214
|
}
|
|
211
215
|
|
|
212
216
|
#onHeaders(...args) {
|
|
213
217
|
assert(!this.#headersSent)
|
|
214
218
|
this.#headersSent = true
|
|
215
|
-
return
|
|
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.#
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
4
|
+
import { Readable } from '@nxtedition/undici'
|
|
5
5
|
|
|
6
6
|
function noop() {}
|
|
7
7
|
|
package/lib/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/nxt-undici",
|
|
3
|
-
"version": "5.
|
|
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.
|
|
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.
|
|
21
|
+
"lint-staged": "^15.4.1",
|
|
23
22
|
"pinst": "^3.0.0",
|
|
24
23
|
"prettier": "^3.4.1",
|
|
25
24
|
"send": "^1.1.0",
|