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 10, 2019
1 parent 850fde3 commit 52544a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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'] &&
res.headers['cache-control'] == null &&
/no-cache/.test(res.headers.pragma)
) {
this._rescc['no-cache'] = true;
Expand Down
11 changes: 11 additions & 0 deletions test/responsetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ 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: {
Expand Down

0 comments on commit 52544a7

Please sign in to comment.