Skip to content

Commit 8450e10

Browse files
committed
fixup
1 parent af0f344 commit 8450e10

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

lib/cache/sqlite-cache-store.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ class SqliteCacheStore {
366366
*/
367367
#findValue (key, canBeExpired = false) {
368368
const url = this.#makeValueUrl(key)
369+
const { headers, method } = key
369370

370371
/**
371372
* @type {SqliteStoreValue[]}
372373
*/
373-
const values = this.#getValuesQuery.all(url, key.method)
374+
const values = this.#getValuesQuery.all(url, method)
374375

375376
if (values.length === 0) {
376-
// No responses, let's just return early
377377
return undefined
378378
}
379379

@@ -386,16 +386,14 @@ class SqliteCacheStore {
386386
let matches = true
387387

388388
if (value.vary) {
389-
if (!key.headers) {
390-
// Request doesn't have headers so it can't fulfill the vary
391-
// requirements no matter what, let's return early
389+
if (!headers) {
392390
return undefined
393391
}
394392

395-
value.vary = JSON.parse(value.vary)
393+
const vary = JSON.parse(value.vary)
396394

397-
for (const header in value.vary) {
398-
if (key.headers[header] !== value.vary[header]) {
395+
for (const header in vary) {
396+
if (headerValueEquals(headers[header], vary[header])) {
399397
matches = false
400398
break
401399
}
@@ -411,6 +409,29 @@ class SqliteCacheStore {
411409
}
412410
}
413411

412+
/**
413+
* @param {string|string[]|null|undefined} lhs
414+
* @param {string|string[]|null|undefined} rhs
415+
* @returns {boolean}
416+
*/
417+
function headerValueEquals (lhs, rhs) {
418+
if (Array.isArray(lhs) && Array.isArray(rhs)) {
419+
if (lhs.length !== rhs.length) {
420+
return false
421+
}
422+
423+
for (let i = 0; i < lhs.length; i++) {
424+
if (lhs[i] !== rhs[i]) {
425+
return false
426+
}
427+
}
428+
429+
return true
430+
}
431+
432+
return lhs === rhs
433+
}
434+
414435
/**
415436
* @param {Buffer[]} buffers
416437
* @returns {string[]}

0 commit comments

Comments
 (0)