Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a max-age=0 patch for some versions of Safari. #9

Merged
merged 1 commit into from Jul 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -36,6 +36,10 @@ function fresh(req, res) {
// check for no-cache cache request directive
if (cc && cc.indexOf('no-cache') !== -1) return false;

// check for max-age=0 cache request directive, which is sent by some
// versions of Safari when a page is reloaded.
if (cc && cc.indexOf('max-age=0') !== -1) return false;

// parse if-none-match
if (noneMatch) noneMatch = noneMatch.split(/ *, */);

Expand All @@ -50,4 +54,4 @@ function fresh(req, res) {
}

return !! (etagMatches && notModified);
}
}
16 changes: 13 additions & 3 deletions test/fresh.js
Expand Up @@ -124,9 +124,19 @@ describe('fresh(reqHeader, resHeader)', function(){

describe('when requested with Cache-Control: no-cache', function(){
it('should be stale', function(){
var req = { 'cache-control' : ' no-cache' };
var res = {};
// use matching etags so it would otherwise be fresh
var req = { 'if-none-match': 'tobi', 'cache-control' : 'no-cache' };
var res = { 'etag': 'tobi' };
fresh(req, res).should.be.false;
})
})

describe('when requested with Cache-Control: max-age=0', function(){
it('should be stale', function(){
// use matching etags so it would otherwise be fresh
var req = { 'if-none-match': 'tobi', 'cache-control' : 'max-age=0' };
var res = { 'etag': 'tobi' };
fresh(req, res).should.be.false;
})
})
})
})