Permalink
Browse files

slight refactor of cache-control logic to be more robust

  • Loading branch information...
jonathanong committed Jul 6, 2014
1 parent 00f25e6 commit 327db5a647ea0a63fd1be41e28cf7879d1e51ca7
Showing with 8 additions and 6 deletions.
  1. +8 −6 index.js
View
@@ -28,17 +28,19 @@ function fresh(req, res) {
var noneMatch = req['if-none-match'];
var lastModified = res['last-modified'];
var etag = res['etag'];
- var cc = req['cache-control'];
// unconditional request
if (!modifiedSince && !noneMatch) return false;
- // check for no-cache cache request directive
- if (cc && cc.indexOf('no-cache') !== -1) return false;
+ var cc = req['cache-control'];
+ if (cc) {
+ // check for no-cache cache request directive
+ if (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;
+ // check for max-age=0 cache request directive, which is sent by some
+ // versions of Safari when a page is reloaded.
+ if (/max-age\s*=\s*0/.test(cc)) return false;
+ }
// parse if-none-match
if (noneMatch) noneMatch = noneMatch.split(/ *, */);

0 comments on commit 327db5a

Please sign in to comment.