@nxtedition/nxt-undici 6.0.5 → 6.0.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.
@@ -5,14 +5,17 @@ const DEFAULT_STORE = new undici.cacheStores.SqliteCacheStore({ location: ':memo
5
5
  const MAX_ENTRY_SIZE = 128 * 1024
6
6
 
7
7
  class CacheHandler extends DecoratorHandler {
8
+ #key
8
9
  #value
9
- #opts
10
10
  #store
11
11
 
12
- constructor(opts, { store, handler }) {
12
+ constructor(key, { store, handler }) {
13
+ undici.util.cache.assertCacheKey(key)
14
+
13
15
  super(handler)
14
16
 
15
- this.#opts = opts
17
+ this.#key = key
18
+ this.#value = null
16
19
  this.#store = store
17
20
  }
18
21
 
@@ -61,7 +64,7 @@ class CacheHandler extends DecoratorHandler {
61
64
  for (const key of [headers.vary]
62
65
  .flat()
63
66
  .flatMap((vary) => vary.split(',').map((key) => key.trim().toLowerCase()))) {
64
- const val = this.#opts.headers?.[key]
67
+ const val = this.#key.headers[key]
65
68
  if (!val) {
66
69
  // Expect vary headers to be present...
67
70
  return super.onHeaders(statusCode, headers, resume)
@@ -115,7 +118,7 @@ class CacheHandler extends DecoratorHandler {
115
118
 
116
119
  onComplete(trailers) {
117
120
  if (this.#value && (!trailers || Object.keys(trailers).length === 0)) {
118
- this.#store.set(this.#opts, this.#value)
121
+ this.#store.set(this.#key, this.#value)
119
122
  }
120
123
 
121
124
  super.onComplete(trailers)
@@ -150,7 +153,10 @@ export default () => (dispatch) => (opts, handler) => {
150
153
  const store = opts.cache.store ?? DEFAULT_STORE
151
154
  const entry = store.get(opts)
152
155
  if (!entry) {
153
- return dispatch(opts, new CacheHandler(opts.headers, { store, handler }))
156
+ return dispatch(
157
+ opts,
158
+ new CacheHandler(undici.util.cache.makeCacheKey(opts), { store, handler }),
159
+ )
154
160
  }
155
161
 
156
162
  let aborted = false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.0.5",
3
+ "version": "6.0.6",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",