@nxtedition/nxt-undici 6.0.22 → 6.0.23

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.
@@ -2,7 +2,7 @@ import undici from '@nxtedition/undici'
2
2
  import { DecoratorHandler, parseCacheControl } from '../utils.js'
3
3
 
4
4
  const DEFAULT_STORE = new undici.cacheStores.SqliteCacheStore({ location: ':memory:' })
5
- const MAX_ENTRY_SIZE = 128 * 1024
5
+ const DEFAULT_MAX_ENTRY_SIZE = 128 * 1024
6
6
  const EMPTY_BUFFER = Buffer.alloc(0)
7
7
  const NOOP = () => {}
8
8
 
@@ -10,8 +10,9 @@ class CacheHandler extends DecoratorHandler {
10
10
  #key
11
11
  #value
12
12
  #store
13
+ #maxEntrySize
13
14
 
14
- constructor(key, { store, handler }) {
15
+ constructor(key, { store, handler, maxEntrySize }) {
15
16
  undici.util.cache.assertCacheKey(key)
16
17
 
17
18
  super(handler)
@@ -19,6 +20,7 @@ class CacheHandler extends DecoratorHandler {
19
20
  this.#key = key
20
21
  this.#value = null
21
22
  this.#store = store
23
+ this.#maxEntrySize = maxEntrySize ?? store.maxEntrySize ?? DEFAULT_MAX_ENTRY_SIZE
22
24
  }
23
25
 
24
26
  onConnect(abort) {
@@ -38,7 +40,7 @@ class CacheHandler extends DecoratorHandler {
38
40
  }
39
41
 
40
42
  const contentLength = headers['content-length'] ? Number(headers['content-length']) : Infinity
41
- if (Number.isFinite(contentLength) && contentLength > MAX_ENTRY_SIZE) {
43
+ if (Number.isFinite(contentLength) && contentLength > DEFAULT_MAX_ENTRY_SIZE) {
42
44
  // We don't support caching responses with body...
43
45
  return super.onHeaders(statusCode, headers, resume)
44
46
  }
@@ -111,7 +113,7 @@ class CacheHandler extends DecoratorHandler {
111
113
  this.#value.size += chunk.length
112
114
  this.#value.body.push(chunk)
113
115
 
114
- if (this.#value.size > MAX_ENTRY_SIZE) {
116
+ if (this.#value.size > this.#maxEntrySize) {
115
117
  this.#value = null
116
118
  this.#value.size = 0
117
119
  }
@@ -162,7 +164,11 @@ export default () => (dispatch) => (opts, handler) => {
162
164
  opts,
163
165
  cacheControlDirectives['no-store']
164
166
  ? handler
165
- : new CacheHandler(undici.util.cache.makeCacheKey(opts), { store, handler }),
167
+ : new CacheHandler(undici.util.cache.makeCacheKey(opts), {
168
+ maxEntrySize: opts.cache.maxEntrySize,
169
+ store,
170
+ handler,
171
+ }),
166
172
  )
167
173
  }
168
174
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "6.0.22",
3
+ "version": "6.0.23",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",