@@ -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,30 @@ 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
+ // TODO (fix): This should also match out of order?
424
+ for ( let i = 0 ; i < lhs . length ; i ++ ) {
425
+ if ( lhs [ i ] !== rhs [ i ] ) {
426
+ return false
427
+ }
428
+ }
429
+
430
+ return true
431
+ }
432
+
433
+ return lhs === rhs
434
+ }
435
+
414
436
/**
415
437
* @param {Buffer[] } buffers
416
438
* @returns {string[] }
0 commit comments