Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 23, 2024
1 parent af0f344 commit 86093a6
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions lib/cache/sqlite-cache-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,14 @@ class SqliteCacheStore {
*/
#findValue (key, canBeExpired = false) {
const url = this.#makeValueUrl(key)
const { headers, method } = key

/**
* @type {SqliteStoreValue[]}
*/
const values = this.#getValuesQuery.all(url, key.method)
const values = this.#getValuesQuery.all(url, method)

if (values.length === 0) {
// No responses, let's just return early
return undefined
}

Expand All @@ -386,16 +386,14 @@ class SqliteCacheStore {
let matches = true

if (value.vary) {
if (!key.headers) {
// Request doesn't have headers so it can't fulfill the vary
// requirements no matter what, let's return early
if (!headers) {
return undefined
}

value.vary = JSON.parse(value.vary)
const vary = JSON.parse(value.vary)

for (const header in value.vary) {
if (key.headers[header] !== value.vary[header]) {
for (const header in vary) {
if (headerValueEquals(headers[header], vary[header])) {
matches = false
break
}
Expand All @@ -411,6 +409,30 @@ class SqliteCacheStore {
}
}

/**
* @param {string|string[]|null|undefined} lhs
* @param {string|string[]|null|undefined} rhs
* @returns {boolean}
*/
function headerValueEquals (lhs, rhs) {
if (Array.isArray(lhs) && Array.isArray(rhs)) {
if (lhs.length !== rhs.length) {
return false
}

// TODO (fix): This should also match out of order?
for (let i = 0; i < lhs.length; i++) {
if (lhs[i] !== rhs[i]) {
return false
}
}

return true
}

return lhs === rhs
}

/**
* @param {Buffer[]} buffers
* @returns {string[]}
Expand Down

0 comments on commit 86093a6

Please sign in to comment.