@nxtedition/nxt-undici 6.2.14 → 6.2.16
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
|
|
@@ -18,6 +17,7 @@ class Handler extends DecoratorHandler {
|
|
|
18
17
|
#headers
|
|
19
18
|
#trailers
|
|
20
19
|
#body
|
|
20
|
+
#bodySize = 0
|
|
21
21
|
|
|
22
22
|
#abort
|
|
23
23
|
#aborted = false
|
|
@@ -48,6 +48,7 @@ class Handler extends DecoratorHandler {
|
|
|
48
48
|
this.#statusCode = 0
|
|
49
49
|
this.#headers = null
|
|
50
50
|
this.#body = null
|
|
51
|
+
this.#bodySize = 0
|
|
51
52
|
this.#trailers = null
|
|
52
53
|
|
|
53
54
|
if (!this.#headersSent) {
|
|
@@ -75,6 +76,11 @@ class Handler extends DecoratorHandler {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
onUpgrade() {
|
|
80
|
+
// TODO (fix): Should we support this?
|
|
81
|
+
throw new Error('not supported')
|
|
82
|
+
}
|
|
83
|
+
|
|
78
84
|
onHeaders(statusCode, headers, resume) {
|
|
79
85
|
this.#statusCode = statusCode
|
|
80
86
|
this.#headers = headers
|
|
@@ -121,6 +127,7 @@ class Handler extends DecoratorHandler {
|
|
|
121
127
|
this.#etag = headers.etag
|
|
122
128
|
} else if (statusCode >= 400) {
|
|
123
129
|
this.#body = []
|
|
130
|
+
this.#bodySize = 0
|
|
124
131
|
return true
|
|
125
132
|
} else {
|
|
126
133
|
this.#headersSent = true
|
|
@@ -146,13 +153,13 @@ class Handler extends DecoratorHandler {
|
|
|
146
153
|
|
|
147
154
|
if (this.#pos > 0 && this.#etag !== headers.etag) {
|
|
148
155
|
this.#maybeError(null)
|
|
149
|
-
return
|
|
156
|
+
return false
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
const contentRange = parseRangeHeader(headers['content-range'])
|
|
153
160
|
if (!contentRange) {
|
|
154
161
|
this.#maybeError(null)
|
|
155
|
-
return
|
|
162
|
+
return false
|
|
156
163
|
}
|
|
157
164
|
|
|
158
165
|
const { start, size, end = size } = contentRange
|
|
@@ -165,6 +172,7 @@ class Handler extends DecoratorHandler {
|
|
|
165
172
|
return true
|
|
166
173
|
} else {
|
|
167
174
|
this.#maybeError(this.#retryError)
|
|
175
|
+
return false
|
|
168
176
|
}
|
|
169
177
|
}
|
|
170
178
|
|
|
@@ -177,7 +185,14 @@ class Handler extends DecoratorHandler {
|
|
|
177
185
|
return super.onData(chunk)
|
|
178
186
|
}
|
|
179
187
|
|
|
180
|
-
this.#body
|
|
188
|
+
if (this.#body) {
|
|
189
|
+
this.#body.push(chunk)
|
|
190
|
+
this.#bodySize += chunk.byteLength
|
|
191
|
+
if (this.#bodySize > 256 * 1024) {
|
|
192
|
+
this.#body = null
|
|
193
|
+
this.#bodySize = 0
|
|
194
|
+
}
|
|
195
|
+
}
|
|
181
196
|
}
|
|
182
197
|
|
|
183
198
|
onComplete(trailers) {
|
|
@@ -351,6 +366,7 @@ class Handler extends DecoratorHandler {
|
|
|
351
366
|
export default () => (dispatch) => (opts, handler) =>
|
|
352
367
|
opts.retry !== false &&
|
|
353
368
|
!opts.upgrade &&
|
|
354
|
-
(/^(HEAD|GET|PUT|PATCH)$/.test(opts.method) || opts.idempotent)
|
|
369
|
+
(/^(HEAD|GET|PUT|PATCH|QUERY)$/.test(opts.method) || opts.idempotent) &&
|
|
370
|
+
opts.idempotent !== false
|
|
355
371
|
? dispatch(opts, new Handler(opts, { handler, dispatch }))
|
|
356
372
|
: dispatch(opts, handler)
|