Skip to content

Commit

Permalink
core(uses-long-cache-ttl): handle multiple cache-control headers (#5745)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinribeiro authored and patrickhulce committed Aug 14, 2018
1 parent 049af19 commit bb44a7d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ class CacheHeaders extends Audit {
/** @type {Map<string, string>} */
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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}),
Expand Down

0 comments on commit bb44a7d

Please sign in to comment.