Skip to content

Commit 747c677

Browse files
committed
Ignore Pragma when Cache-Control is present but blank
1 parent d5c28b7 commit 747c677

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports = class CachePolicy {
8585

8686
// When the Cache-Control header field is not present in a request, caches MUST consider the no-cache request pragma-directive
8787
// as having the same effect as if "Cache-Control: no-cache" were present (see Section 5.2.1).
88-
if (!res.headers['cache-control'] && /no-cache/.test(res.headers.pragma)) {
88+
if (res.headers['cache-control'] == null && /no-cache/.test(res.headers.pragma)) {
8989
this._rescc['no-cache'] = true;
9090
}
9191
}

test/responsetest.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,15 @@ describe('Response headers', function() {
223223
assert(cache.stale());
224224
});
225225

226+
it('blank cache-control and pragma: no-cache', function() {
227+
const cache = new CachePolicy(req, {headers:{
228+
'cache-control': '',
229+
'pragma': 'no-cache',
230+
'last-modified': new Date().toGMTString(),
231+
}});
232+
assert(!cache.stale());
233+
});
234+
226235
it('no-store', function() {
227236
const cache = new CachePolicy(req, {headers:{
228237
'cache-control': 'no-store, public, max-age=1',

0 commit comments

Comments
 (0)