@@ -366,14 +366,14 @@ class SqliteCacheStore {
366
366
*/
367
367
#findValue ( key , canBeExpired = false ) {
368
368
const url = this . #makeValueUrl( key )
369
+ const { headers, method } = key
369
370
370
371
/**
371
372
* @type {SqliteStoreValue[] }
372
373
*/
373
- const values = this . #getValuesQuery. all ( url , key . method )
374
+ const values = this . #getValuesQuery. all ( url , method )
374
375
375
376
if ( values . length === 0 ) {
376
- // No responses, let's just return early
377
377
return undefined
378
378
}
379
379
@@ -386,16 +386,14 @@ class SqliteCacheStore {
386
386
let matches = true
387
387
388
388
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 ) {
392
390
return undefined
393
391
}
394
392
395
- value . vary = JSON . parse ( value . vary )
393
+ const vary = JSON . parse ( value . vary )
396
394
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 ] ) ) {
399
397
matches = false
400
398
break
401
399
}
@@ -411,6 +409,29 @@ class SqliteCacheStore {
411
409
}
412
410
}
413
411
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
+
414
435
/**
415
436
* @param {Buffer[] } buffers
416
437
* @returns {string[] }
0 commit comments