Skip to content

Commit

Permalink
Ignore Pragma when Cache-Control is present but blank
Browse files Browse the repository at this point in the history
  • Loading branch information
robhanlon22 committed Feb 9, 2019
1 parent d5c28b7 commit 747c677
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = class CachePolicy {

// When the Cache-Control header field is not present in a request, caches MUST consider the no-cache request pragma-directive
// as having the same effect as if "Cache-Control: no-cache" were present (see Section 5.2.1).
if (!res.headers['cache-control'] && /no-cache/.test(res.headers.pragma)) {
if (res.headers['cache-control'] == null && /no-cache/.test(res.headers.pragma)) {
this._rescc['no-cache'] = true;
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/responsetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ describe('Response headers', function() {
assert(cache.stale());
});

it('blank cache-control and pragma: no-cache', function() {
const cache = new CachePolicy(req, {headers:{
'cache-control': '',
'pragma': 'no-cache',
'last-modified': new Date().toGMTString(),
}});
assert(!cache.stale());
});

it('no-store', function() {
const cache = new CachePolicy(req, {headers:{
'cache-control': 'no-store, public, max-age=1',
Expand Down

0 comments on commit 747c677

Please sign in to comment.