diff --git a/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js b/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js index 32462e039c24..bbea54ac7c17 100644 --- a/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js +++ b/lighthouse-core/audits/byte-efficiency/uses-long-cache-ttl.js @@ -185,7 +185,13 @@ class CacheHeaders extends Audit { /** @type {Map} */ const headers = new Map(); for (const header of record.responseHeaders || []) { - headers.set(header.name.toLowerCase(), header.value); + if (headers.has(header.name.toLowerCase())) { + const previousHeaderValue = headers.get(header.name.toLowerCase()); + headers.set(header.name.toLowerCase(), + `${previousHeaderValue}, ${header.value}`); + } else { + headers.set(header.name.toLowerCase(), header.value); + } } const cacheControl = parseCacheControl(headers.get('cache-control')); diff --git a/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js b/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js index 148fa6df213f..d49bae881c1b 100644 --- a/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js +++ b/lighthouse-core/test/audits/byte-efficiency/uses-long-cache-ttl-test.js @@ -119,6 +119,25 @@ describe('Cache headers audit', () => { }); }); + it('respects multiple cache-control headers', () => { + networkRecords = [ + networkRecord({headers: { + 'cache-control': 'max-age=31536000, public', + 'Cache-control': 'no-transform', + }}), + networkRecord({headers: { + 'Cache-Control': 'no-transform', + 'cache-control': 'max-age=3600', + 'Cache-control': 'public', + }}), + ]; + + return CacheHeadersAudit.audit(artifacts, {options}).then(result => { + const items = result.extendedInfo.value.results; + assert.equal(items.length, 1); + }); + }); + it('catches records with Etags', () => { networkRecords = [ networkRecord({headers: {etag: 'md5hashhere'}}),