@nxtedition/nxt-undici 6.2.15 → 6.2.17
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.
|
@@ -4,7 +4,6 @@ import { DecoratorHandler, isDisturbed, decorateError, parseRangeHeader } from '
|
|
|
4
4
|
|
|
5
5
|
function noop() {}
|
|
6
6
|
|
|
7
|
-
// TODO (fix): What about onUpgrade?
|
|
8
7
|
class Handler extends DecoratorHandler {
|
|
9
8
|
#dispatch
|
|
10
9
|
#opts
|
|
@@ -77,6 +76,11 @@ class Handler extends DecoratorHandler {
|
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
|
|
79
|
+
onUpgrade() {
|
|
80
|
+
// TODO (fix): Should we support this?
|
|
81
|
+
throw new Error('not supported')
|
|
82
|
+
}
|
|
83
|
+
|
|
80
84
|
onHeaders(statusCode, headers, resume) {
|
|
81
85
|
this.#statusCode = statusCode
|
|
82
86
|
this.#headers = headers
|
|
@@ -149,13 +153,13 @@ class Handler extends DecoratorHandler {
|
|
|
149
153
|
|
|
150
154
|
if (this.#pos > 0 && this.#etag !== headers.etag) {
|
|
151
155
|
this.#maybeError(null)
|
|
152
|
-
return
|
|
156
|
+
return false
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
const contentRange = parseRangeHeader(headers['content-range'])
|
|
156
160
|
if (!contentRange) {
|
|
157
161
|
this.#maybeError(null)
|
|
158
|
-
return
|
|
162
|
+
return false
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
const { start, size, end = size } = contentRange
|
|
@@ -168,6 +172,7 @@ class Handler extends DecoratorHandler {
|
|
|
168
172
|
return true
|
|
169
173
|
} else {
|
|
170
174
|
this.#maybeError(this.#retryError)
|
|
175
|
+
return false
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
|
|
@@ -247,29 +252,26 @@ class Handler extends DecoratorHandler {
|
|
|
247
252
|
let retryPromise
|
|
248
253
|
try {
|
|
249
254
|
if (typeof this.#opts.retry === 'function') {
|
|
250
|
-
retryPromise =
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
255
|
+
retryPromise = Promise.resolve(
|
|
256
|
+
this.#opts.retry(
|
|
257
|
+
decorateError(err, this.#opts, {
|
|
258
|
+
statusCode: this.#statusCode,
|
|
259
|
+
headers: this.#headers,
|
|
260
|
+
trailers: this.#trailers,
|
|
261
|
+
body: this.#body,
|
|
262
|
+
}),
|
|
263
|
+
this.#retryCount,
|
|
264
|
+
this.#opts,
|
|
265
|
+
() => this.#retryFn(err, this.#retryCount, this.#opts),
|
|
266
|
+
),
|
|
260
267
|
)
|
|
261
268
|
} else {
|
|
262
|
-
retryPromise = this.#retryFn(err, this.#retryCount, this.#opts)
|
|
269
|
+
retryPromise = Promise.resolve(this.#retryFn(err, this.#retryCount, this.#opts))
|
|
263
270
|
}
|
|
264
271
|
} catch (err) {
|
|
265
272
|
retryPromise = Promise.reject(err)
|
|
266
273
|
}
|
|
267
274
|
|
|
268
|
-
if (retryPromise == null) {
|
|
269
|
-
this.#maybeError(err)
|
|
270
|
-
return
|
|
271
|
-
}
|
|
272
|
-
|
|
273
275
|
retryPromise
|
|
274
276
|
.then((shouldRetry) => {
|
|
275
277
|
if (this.#aborted) {
|
|
@@ -361,6 +363,7 @@ class Handler extends DecoratorHandler {
|
|
|
361
363
|
export default () => (dispatch) => (opts, handler) =>
|
|
362
364
|
opts.retry !== false &&
|
|
363
365
|
!opts.upgrade &&
|
|
364
|
-
(/^(HEAD|GET|PUT|PATCH)$/.test(opts.method) || opts.idempotent)
|
|
366
|
+
(/^(HEAD|GET|PUT|PATCH|QUERY)$/.test(opts.method) || opts.idempotent) &&
|
|
367
|
+
opts.idempotent !== false
|
|
365
368
|
? dispatch(opts, new Handler(opts, { handler, dispatch }))
|
|
366
369
|
: dispatch(opts, handler)
|