@@ -248,7 +248,7 @@ class SqliteCacheStore {
248248 const body = [ ]
249249 const store = this
250250
251- const writable = new Writable ( {
251+ return new Writable ( {
252252 write ( chunk , encoding , callback ) {
253253 if ( typeof chunk === 'string' ) {
254254 chunk = Buffer . from ( chunk , encoding )
@@ -267,9 +267,6 @@ class SqliteCacheStore {
267267 final ( callback ) {
268268 store . prune ( )
269269
270- /**
271- * @type {SqliteStoreValue | undefined }
272- */
273270 const existingValue = store . #findValue( key , true )
274271 if ( existingValue ) {
275272 // Updating an existing response, let's overwrite it
@@ -306,8 +303,6 @@ class SqliteCacheStore {
306303 callback ( )
307304 }
308305 } )
309-
310- return writable
311306 }
312307
313308 /**
@@ -373,14 +368,14 @@ class SqliteCacheStore {
373368 */
374369 #findValue ( key , canBeExpired = false ) {
375370 const url = this . #makeValueUrl( key )
371+ const { headers, method } = key
376372
377373 /**
378374 * @type {SqliteStoreValue[] }
379375 */
380- const values = this . #getValuesQuery. all ( url , key . method )
376+ const values = this . #getValuesQuery. all ( url , method )
381377
382378 if ( values . length === 0 ) {
383- // No responses, let's just return early
384379 return undefined
385380 }
386381
@@ -393,16 +388,14 @@ class SqliteCacheStore {
393388 let matches = true
394389
395390 if ( value . vary ) {
396- if ( ! key . headers ) {
397- // Request doesn't have headers so it can't fulfill the vary
398- // requirements no matter what, let's return early
391+ if ( ! headers ) {
399392 return undefined
400393 }
401394
402- value . vary = JSON . parse ( value . vary )
395+ const vary = JSON . parse ( value . vary )
403396
404- for ( const header in value . vary ) {
405- if ( key . headers [ header ] !== value . vary [ header ] ) {
397+ for ( const header in vary ) {
398+ if ( headerValueEquals ( headers [ header ] , vary [ header ] ) ) {
406399 matches = false
407400 break
408401 }
@@ -418,6 +411,29 @@ class SqliteCacheStore {
418411 }
419412}
420413
414+ /**
415+ * @param {string|string[]|null|undefined } lhs
416+ * @param {string|string[]|null|undefined } rhs
417+ * @returns {boolean }
418+ */
419+ function headerValueEquals ( lhs , rhs ) {
420+ if ( Array . isArray ( lhs ) && Array . isArray ( rhs ) ) {
421+ if ( lhs . length !== rhs . length ) {
422+ return false
423+ }
424+
425+ for ( let i = 0 ; i < lhs . length ; i ++ ) {
426+ if ( rhs . includes ( lhs [ i ] ) ) {
427+ return false
428+ }
429+ }
430+
431+ return true
432+ }
433+
434+ return lhs === rhs
435+ }
436+
421437/**
422438 * @param {Buffer[] } buffers
423439 * @returns {string[] }
0 commit comments