Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 6, 2024
1 parent ea5e09c commit 4a1a366
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/handler/cache-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ class CacheHandler extends DecoratorHandler {
const headers = util.parseHeaders(rawHeaders)

const cacheControlHeader = headers['cache-control']
const contentLengthHeader = headers['content-length']

if (!cacheControlHeader || !contentLengthHeader || this.#store.isFull) {
// Don't have the headers we need, can't cache
if (!cacheControlHeader || typeof cacheControlHeader !== 'string') {
// Don't have cache-control, can't cache.
return downstreamOnHeaders()
}

const contentLength = Number(contentLengthHeader)
const contentLengthHeader = headers['content-length']
const contentLength = contentLengthHeader ? Number(contentLengthHeader) : null
if (!Number.isInteger(contentLength)) {
// Don't know the final size, don't cache.
// TODO (fix): Why not cache?
return downstreamOnHeaders()
}

Expand Down
2 changes: 1 addition & 1 deletion types/cache-interceptor.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ declare namespace CacheHandler {
export interface CacheStoreValue {
statusCode: number;
statusMessage: string;
rawHeaders: Buffer[];
rawHeaders: (Buffer | Buffer[])[];
rawTrailers?: string[];
/**
* Headers defined by the Vary header and their respective values for
Expand Down

0 comments on commit 4a1a366

Please sign in to comment.