diff --git a/index.js b/index.js index 9c3f47d..2d6ed4a 100644 --- a/index.js +++ b/index.js @@ -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(/ *, */); @@ -50,4 +54,4 @@ function fresh(req, res) { } return !! (etagMatches && notModified); -} \ No newline at end of file +} diff --git a/test/fresh.js b/test/fresh.js index 2c46693..572e31b 100644 --- a/test/fresh.js +++ b/test/fresh.js @@ -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; }) }) -}) \ No newline at end of file +})