@nxtedition/nxt-undici 6.1.4 → 6.1.6
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/cache.js +17 -13
- package/lib/utils.js +13 -4
- package/package.json +1 -1
package/lib/interceptor/cache.js
CHANGED
|
@@ -190,22 +190,26 @@ export default () => (dispatch) => (opts, handler) => {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
handler.onHeaders(statusCode, headers, NOOP)
|
|
199
|
-
if (aborted) {
|
|
200
|
-
return
|
|
201
|
-
}
|
|
193
|
+
try {
|
|
194
|
+
handler.onConnect(abort)
|
|
195
|
+
if (aborted) {
|
|
196
|
+
return
|
|
197
|
+
}
|
|
202
198
|
|
|
203
|
-
|
|
204
|
-
handler.onData(body)
|
|
199
|
+
handler.onHeaders(statusCode, headers, NOOP)
|
|
205
200
|
if (aborted) {
|
|
206
201
|
return
|
|
207
202
|
}
|
|
208
|
-
}
|
|
209
203
|
|
|
210
|
-
|
|
204
|
+
if (body?.byteLength) {
|
|
205
|
+
handler.onData(body)
|
|
206
|
+
if (aborted) {
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
handler.onComplete({})
|
|
212
|
+
} catch (err) {
|
|
213
|
+
abort(err)
|
|
214
|
+
}
|
|
211
215
|
}
|
package/lib/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import cacheControlParser from 'cache-control-parser'
|
|
2
2
|
import stream from 'node:stream'
|
|
3
|
+
import assert from 'node:assert'
|
|
3
4
|
import { util } from '@nxtedition/undici'
|
|
4
5
|
|
|
5
6
|
let fastNow = Date.now()
|
|
@@ -200,6 +201,7 @@ export class DecoratorHandler {
|
|
|
200
201
|
#handler
|
|
201
202
|
#aborted = false
|
|
202
203
|
#errored = false
|
|
204
|
+
#completed = false
|
|
203
205
|
|
|
204
206
|
constructor(handler) {
|
|
205
207
|
if (typeof handler !== 'object' || handler === null) {
|
|
@@ -211,10 +213,13 @@ export class DecoratorHandler {
|
|
|
211
213
|
onConnect(abort) {
|
|
212
214
|
this.#aborted = false
|
|
213
215
|
this.#errored = false
|
|
216
|
+
this.#completed = false
|
|
214
217
|
|
|
215
218
|
return this.#handler.onConnect?.((reason) => {
|
|
216
|
-
this.#aborted
|
|
217
|
-
|
|
219
|
+
if (!this.#aborted && !this.#completed && !this.#errored) {
|
|
220
|
+
this.#aborted = true
|
|
221
|
+
abort(reason)
|
|
222
|
+
}
|
|
218
223
|
})
|
|
219
224
|
}
|
|
220
225
|
|
|
@@ -232,19 +237,23 @@ export class DecoratorHandler {
|
|
|
232
237
|
|
|
233
238
|
onData(data) {
|
|
234
239
|
if (!this.#aborted && !this.#errored && data != null) {
|
|
240
|
+
assert(!this.#completed)
|
|
235
241
|
return this.#handler.onData?.(data)
|
|
236
242
|
}
|
|
237
243
|
}
|
|
238
244
|
|
|
239
245
|
onComplete(trailers) {
|
|
240
|
-
if (!this.#aborted && !this.#
|
|
246
|
+
if (!this.#aborted && !this.#completed) {
|
|
247
|
+
this.#completed = true
|
|
248
|
+
assert(!this.#errored)
|
|
241
249
|
return this.#handler.onComplete?.(trailers)
|
|
242
250
|
}
|
|
243
251
|
}
|
|
244
252
|
|
|
245
253
|
onError(err) {
|
|
246
|
-
if (!this.#errored) {
|
|
254
|
+
if (!this.#errored && !this.#completed) {
|
|
247
255
|
this.#errored = true
|
|
256
|
+
assert(!this.#completed)
|
|
248
257
|
return this.#handler.onError?.(err)
|
|
249
258
|
}
|
|
250
259
|
}
|