@nxtedition/nxt-undici 6.0.21 → 6.0.22

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,6 +4,7 @@ import { DecoratorHandler, parseCacheControl } from '../utils.js'
4
4
  const DEFAULT_STORE = new undici.cacheStores.SqliteCacheStore({ location: ':memory:' })
5
5
  const MAX_ENTRY_SIZE = 128 * 1024
6
6
  const EMPTY_BUFFER = Buffer.alloc(0)
7
+ const NOOP = () => {}
7
8
 
8
9
  class CacheHandler extends DecoratorHandler {
9
10
  #key
@@ -175,27 +176,20 @@ export default () => (dispatch) => (opts, handler) => {
175
176
  }
176
177
  }
177
178
 
178
- let state = 0
179
-
180
- const resume = () => {
181
- try {
182
- let paused = false
183
- while (!paused && !aborted) {
184
- state += 1
185
- if (state === 1) {
186
- handler.onConnect(abort)
187
- } else if (state === 2) {
188
- paused = handler.onHeaders(statusCode, headers, resume) === false
189
- } else if (state === 3) {
190
- paused = handler.onData(body ?? EMPTY_BUFFER) === false
191
- } else if (state === 4) {
192
- handler.onComplete({})
193
- }
194
- }
195
- } catch (err) {
196
- abort(err)
197
- }
179
+ handler.onConnect(abort)
180
+ if (aborted) {
181
+ return
182
+ }
183
+
184
+ handler.onHeaders(statusCode, headers, NOOP)
185
+ if (aborted) {
186
+ return
187
+ }
188
+
189
+ handler.onData(body ?? EMPTY_BUFFER)
190
+ if (aborted) {
191
+ return
198
192
  }
199
193
 
200
- resume()
194
+ handler.onComplete({})
201
195
  }
package/lib/utils.js CHANGED
@@ -276,15 +276,15 @@ export class DecoratorHandler {
276
276
  })
277
277
  }
278
278
 
279
- onUpgrade(...args) {
279
+ onUpgrade(statusCode, headers, socket) {
280
280
  if (!this.#aborted && !this.#errored) {
281
- return this.#handler.onUpgrade?.(...args)
281
+ return this.#handler.onUpgrade?.(statusCode, headers, socket)
282
282
  }
283
283
  }
284
284
 
285
- onHeaders(...args) {
285
+ onHeaders(statusCode, headers, resume) {
286
286
  if (!this.#aborted && !this.#errored) {
287
- return this.#handler.onHeaders?.(...args)
287
+ return this.#handler.onHeaders?.(statusCode, headers, resume)
288
288
  }
289
289
  }
290
290
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.0.21",
3
+ "version": "6.0.22",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",