diff --git a/lib/cache/memory-cache-store.js b/lib/cache/memory-cache-store.js index fd9927ba169..ae6d6614d82 100644 --- a/lib/cache/memory-cache-store.js +++ b/lib/cache/memory-cache-store.js @@ -366,7 +366,7 @@ class MemoryStoreWritableStream extends Writable { super() this.#value = value this.#value.readLock = true - this.#maxEntrySize = maxEntrySize + this.#maxEntrySize = maxEntrySize ?? Infinity } get rawTrailers () { @@ -374,7 +374,7 @@ class MemoryStoreWritableStream extends Writable { } /** - * @param {Buffer[] | undefined} trailers + * @param {string[] | undefined} trailers */ set rawTrailers (trailers) { this.#value.opts.rawTrailers = trailers diff --git a/lib/core/constants.js b/lib/core/constants.js index e450fc6087e..088cf47d80f 100644 --- a/lib/core/constants.js +++ b/lib/core/constants.js @@ -112,11 +112,14 @@ Object.setPrototypeOf(headerNameLowerCasedRecord, null) */ const wellknownHeaderNameBuffers = {} +// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`. +Object.setPrototypeOf(wellknownHeaderNameBuffers, null) + /** * @param {string} header Lowercased header * @returns {Buffer} */ -function getWellknownHeaderNameBuffer (header) { +function getHeaderNameAsBuffer (header) { let buffer = wellknownHeaderNameBuffers[header] if (buffer === undefined) { @@ -136,6 +139,5 @@ for (let i = 0; i < wellknownHeaderNames.length; ++i) { module.exports = { wellknownHeaderNames, headerNameLowerCasedRecord, - wellknownHeaderNameBuffers, - getWellknownHeaderNameBuffer + getHeaderNameAsBuffer } diff --git a/lib/core/util.js b/lib/core/util.js index 07a198f1fab..c37f213349b 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -10,7 +10,7 @@ const nodeUtil = require('node:util') const { stringify } = require('node:querystring') const { EventEmitter: EE } = require('node:events') const { InvalidArgumentError } = require('./errors') -const { headerNameLowerCasedRecord, getWellknownHeaderNameBuffer } = require('./constants') +const { headerNameLowerCasedRecord, getHeaderNameAsBuffer } = require('./constants') const { tree } = require('./tree') const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(v)) @@ -462,7 +462,7 @@ function encodeHeaders (headers) { rawValue = Buffer.from(value) } - const headerBuffer = getWellknownHeaderNameBuffer(header) + const headerBuffer = getHeaderNameAsBuffer(header) rawHeaders[rawHeadersIndex] = headerBuffer rawHeadersIndex++ diff --git a/lib/handler/cache-handler.js b/lib/handler/cache-handler.js index 91b2d65ef5e..ddf8a1171bc 100644 --- a/lib/handler/cache-handler.js +++ b/lib/handler/cache-handler.js @@ -59,22 +59,19 @@ class CacheHandler extends DecoratorHandler { * @param {Buffer[]} rawHeaders * @param {() => void} resume * @param {string} statusMessage - * @param {Record | undefined} headers * @returns {boolean} */ onHeaders ( statusCode, rawHeaders, resume, - statusMessage, - headers = util.parseHeaders(rawHeaders) + statusMessage ) { const downstreamOnHeaders = () => this.#handler.onHeaders( statusCode, rawHeaders, resume, - statusMessage, - headers + statusMessage ) if ( @@ -101,6 +98,8 @@ class CacheHandler extends DecoratorHandler { return downstreamOnHeaders() } + const headers = util.parseHeaders(rawHeaders) + const cacheControlHeader = headers['cache-control'] const contentLengthHeader = headers['content-length'] diff --git a/lib/handler/cache-revalidation-handler.js b/lib/handler/cache-revalidation-handler.js index cb335d5bb31..4be61477a51 100644 --- a/lib/handler/cache-revalidation-handler.js +++ b/lib/handler/cache-revalidation-handler.js @@ -49,15 +49,13 @@ class CacheRevalidationHandler extends DecoratorHandler { * @param {Buffer[]} rawHeaders * @param {() => void} resume * @param {string} statusMessage - * @param {string[] | undefined} headers * @returns {boolean} */ onHeaders ( statusCode, rawHeaders, resume, - statusMessage, - headers = undefined + statusMessage ) { // https://www.rfc-editor.org/rfc/rfc9111.html#name-handling-a-validation-respo if (statusCode === 304) { @@ -71,8 +69,7 @@ class CacheRevalidationHandler extends DecoratorHandler { statusCode, rawHeaders, resume, - statusMessage, - headers + statusMessage ) } }