@nxtedition/nxt-undici 6.0.18 → 6.0.20
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/interceptor/response-retry.js +11 -7
- package/lib/request.js +10 -7
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@ class Handler extends DecoratorHandler {
|
|
|
13
13
|
#abort
|
|
14
14
|
#aborted = false
|
|
15
15
|
#reason
|
|
16
|
+
#resume
|
|
16
17
|
|
|
17
18
|
#pos
|
|
18
19
|
#end
|
|
@@ -41,6 +42,7 @@ class Handler extends DecoratorHandler {
|
|
|
41
42
|
this.#end = null
|
|
42
43
|
this.#etag = null
|
|
43
44
|
this.#error = null
|
|
45
|
+
this.#resume = null
|
|
44
46
|
|
|
45
47
|
super.onConnect((reason) => {
|
|
46
48
|
if (!this.#aborted) {
|
|
@@ -62,6 +64,8 @@ class Handler extends DecoratorHandler {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
onHeaders(statusCode, headers, resume) {
|
|
67
|
+
this.#resume = resume
|
|
68
|
+
|
|
65
69
|
if (this.#error == null) {
|
|
66
70
|
assert(this.#etag == null)
|
|
67
71
|
assert(this.#pos == null)
|
|
@@ -69,18 +73,18 @@ class Handler extends DecoratorHandler {
|
|
|
69
73
|
assert(this.#headersSent === false)
|
|
70
74
|
|
|
71
75
|
if (headers.trailer) {
|
|
72
|
-
return this.#onHeaders(statusCode, headers
|
|
76
|
+
return this.#onHeaders(statusCode, headers)
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
const contentLength = headers['content-length'] ? Number(headers['content-length']) : null
|
|
76
80
|
if (contentLength != null && !Number.isFinite(contentLength)) {
|
|
77
|
-
return this.#onHeaders(statusCode, headers
|
|
81
|
+
return this.#onHeaders(statusCode, headers)
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
if (statusCode === 206) {
|
|
81
85
|
const range = parseRangeHeader(headers['content-range'])
|
|
82
86
|
if (!range) {
|
|
83
|
-
return this.#onHeaders(statusCode, headers
|
|
87
|
+
return this.#onHeaders(statusCode, headers)
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
const { start, size, end = size } = range
|
|
@@ -100,7 +104,7 @@ class Handler extends DecoratorHandler {
|
|
|
100
104
|
this.#end = contentLength
|
|
101
105
|
this.#etag = headers.etag
|
|
102
106
|
} else {
|
|
103
|
-
return this.#onHeaders(statusCode, headers
|
|
107
|
+
return this.#onHeaders(statusCode, headers)
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
// Weak etags are not useful for comparison nor cache
|
|
@@ -113,7 +117,7 @@ class Handler extends DecoratorHandler {
|
|
|
113
117
|
assert(Number.isFinite(this.#pos))
|
|
114
118
|
assert(this.#end == null || Number.isFinite(this.#end))
|
|
115
119
|
|
|
116
|
-
return this.#onHeaders(statusCode, headers
|
|
120
|
+
return this.#onHeaders(statusCode, headers)
|
|
117
121
|
} else if (statusCode === 206 || (this.#pos === 0 && statusCode === 200)) {
|
|
118
122
|
assert(this.#etag != null || !this.#pos)
|
|
119
123
|
|
|
@@ -207,10 +211,10 @@ class Handler extends DecoratorHandler {
|
|
|
207
211
|
super.onError(err)
|
|
208
212
|
}
|
|
209
213
|
|
|
210
|
-
#onHeaders(statusCode, headers
|
|
214
|
+
#onHeaders(statusCode, headers) {
|
|
211
215
|
assert(!this.#headersSent)
|
|
212
216
|
this.#headersSent = true
|
|
213
|
-
return super.onHeaders(statusCode, headers, resume)
|
|
217
|
+
return super.onHeaders(statusCode, headers, () => this.#resume?.())
|
|
214
218
|
}
|
|
215
219
|
}
|
|
216
220
|
|
package/lib/request.js
CHANGED
|
@@ -143,7 +143,16 @@ export class RequestHandler {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
export function request(dispatch, url, opts) {
|
|
146
|
-
if (
|
|
146
|
+
if (typeof url === 'object' && url != null && opts == null) {
|
|
147
|
+
opts = url
|
|
148
|
+
url = opts.url ?? opts
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (typeof url === 'string') {
|
|
152
|
+
url = new URL(url)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (url == null || typeof url !== 'object') {
|
|
147
156
|
throw new InvalidArgumentError('invalid url')
|
|
148
157
|
}
|
|
149
158
|
|
|
@@ -151,12 +160,6 @@ export function request(dispatch, url, opts) {
|
|
|
151
160
|
throw new InvalidArgumentError('invalid opts')
|
|
152
161
|
}
|
|
153
162
|
|
|
154
|
-
if (typeof url === 'string') {
|
|
155
|
-
url = new URL(url)
|
|
156
|
-
} else if (typeof url === 'object' && url != null && opts == null) {
|
|
157
|
-
opts = url
|
|
158
|
-
}
|
|
159
|
-
|
|
160
163
|
let origin = url.origin
|
|
161
164
|
if (!origin) {
|
|
162
165
|
const protocol = url.protocol ?? 'http:'
|