Permalink
Browse files

Merge pull request #2 from paulwalker/no-cache

return __false__ when request includes Cache-Control: no-cache
  • Loading branch information...
2 parents fee9a28 + 0ea3ea4 commit e9d2d60ca9b4f32528393fe13d52177f59668bff @tj tj committed Aug 10, 2013
Showing with 12 additions and 0 deletions.
  1. +4 −0 index.js
  2. +8 −0 test/fresh.js
View
@@ -28,10 +28,14 @@ function fresh(req, res) {
var noneMatch = req['if-none-match'];
var lastModified = res['last-modified'];
var etag = res['etag'];
+ var cacheControl = req['cache-control'];
// unconditional request
if (!modifiedSince && !noneMatch) return false;
+ // check for no-cache cache request directive
+ if (cacheControl && cacheControl.indexOf('no-cache') !== -1) return false;
+
// parse if-none-match
if (noneMatch) noneMatch = noneMatch.split(/ *, */);
View
@@ -121,4 +121,12 @@ 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 = {};
+ fresh(req, res).should.be.false;
+ })
+ })
})

0 comments on commit e9d2d60

Please sign in to comment.