Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
Signed-off-by: flakey5 <[email protected]>
  • Loading branch information
flakey5 committed Jan 27, 2025
1 parent ef6267d commit 0461a7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
30 changes: 14 additions & 16 deletions lib/handler/cache-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CacheHandler {
statusMessage
)

if (
if (

Check failure on line 100 in lib/handler/cache-handler.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 6
!util.safeHTTPMethods.includes(this.#cacheKey.method) &&
statusCode >= 200 &&
statusCode <= 399
Expand All @@ -112,13 +112,11 @@ class CacheHandler {
return downstreamOnHeaders()
}

const resHeadersLowercase = makeHeaderNamesLowercase(resHeaders)

const cacheControlHeader = resHeadersLowercase['cache-control']
const heuristicallyCacheable = resHeadersLowercase['last-modified'] && HEURISTICALLY_CACHEABLE_STATUS_CODES.includes(statusCode)
const cacheControlHeader = resHeaders['cache-control']
const heuristicallyCacheable = resHeaders['last-modified'] && HEURISTICALLY_CACHEABLE_STATUS_CODES.includes(statusCode)
if (
!cacheControlHeader &&
!resHeadersLowercase.expires &&
!resHeaders.expires &&
!heuristicallyCacheable &&
!this.#cacheByDefault
) {
Expand All @@ -128,23 +126,23 @@ class CacheHandler {
}

const cacheControlDirectives = cacheControlHeader ? parseCacheControlHeader(cacheControlHeader) : {}
if (!canCacheResponse(this.#cacheType, statusCode, resHeadersLowercase, cacheControlDirectives)) {
if (!canCacheResponse(this.#cacheType, statusCode, resHeaders, cacheControlDirectives)) {
return downstreamOnHeaders()
}

const now = Date.now()
const resAge = resHeadersLowercase.age ? getAge(resHeadersLowercase.age) : undefined
const resAge = resHeaders.age ? getAge(resHeaders.age) : undefined
if (resAge && resAge >= MAX_RESPONSE_AGE) {
// Response considered stale
return downstreamOnHeaders()
}

const resDate = typeof resHeadersLowercase.date === 'string'
? parseHttpDate(resHeadersLowercase.date)
const resDate = typeof resHeaders.date === 'string'
? parseHttpDate(resHeaders.date)
: undefined

const staleAt =
determineStaleAt(this.#cacheType, now, resAge, resHeadersLowercase, resDate, cacheControlDirectives) ??
determineStaleAt(this.#cacheType, now, resAge, resHeaders, resDate, cacheControlDirectives) ??
this.#cacheByDefault
if (staleAt === undefined || (resAge && resAge > staleAt)) {
return downstreamOnHeaders()
Expand All @@ -158,8 +156,8 @@ class CacheHandler {
}

let varyDirectives
if (this.#cacheKey.headers && resHeadersLowercase.vary) {
varyDirectives = parseVaryHeader(resHeadersLowercase.vary, this.#cacheKey.headers)
if (this.#cacheKey.headers && resHeaders.vary) {
varyDirectives = parseVaryHeader(resHeaders.vary, this.#cacheKey.headers)

if (!varyDirectives) {
// Parse error
Expand All @@ -168,7 +166,7 @@ class CacheHandler {
}

const deleteAt = determineDeleteAt(baseTime, cacheControlDirectives, absoluteStaleAt)
const strippedHeaders = stripNecessaryHeaders(resHeadersLowercase, cacheControlDirectives)
const strippedHeaders = stripNecessaryHeaders(resHeaders, cacheControlDirectives)

/**
* @type {import('../../types/cache-interceptor.d.ts').default.CacheValue}
Expand All @@ -184,8 +182,8 @@ class CacheHandler {
deleteAt
}

if (typeof resHeadersLowercase.etag === 'string' && isEtagUsable(resHeadersLowercase.etag)) {
value.etag = resHeadersLowercase.etag
if (typeof resHeaders.etag === 'string' && isEtagUsable(resHeaders.etag)) {
value.etag = resHeaders.etag
}

this.#writeStream = this.#store.createWriteStream(this.#cacheKey, value)
Expand Down
2 changes: 1 addition & 1 deletion lib/interceptor/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ module.exports = (opts = {}) => {
// Not a method we want to cache or we don't have the origin, skip
return dispatch(opts, handler)
}

console.log('reqHeaders=', opts.headers)

Check failure on line 321 in lib/interceptor/cache.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 0
const reqCacheControl = opts.headers?.['cache-control']
? parseCacheControlHeader(opts.headers['cache-control'])
: undefined
Expand Down
5 changes: 5 additions & 0 deletions tmp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Client, interceptors } from './index.js'

Check failure on line 1 in tmp.mjs

View workflow job for this annotation

GitHub Actions / Lint

Multiple spaces found before 'from'

const client = new Client('https://google.com').compose(interceptors.cache())

await client.request({ path: '/', method: 'GET', origin: 'google.com' })

0 comments on commit 0461a7f

Please sign in to comment.