Skip to content

Commit

Permalink
Fixed staticCache() when Cookie is present
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 25, 2012
1 parent f4edd9e commit e3aa033
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/middleware/staticCache.js
Expand Up @@ -59,6 +59,7 @@ module.exports = function staticCache(options){
return function staticCache(req, res, next){
var key = cacheKey(req)
, ranges = req.headers.range
, hasCookies = req.headers.cookie
, hit = cache.get(key);

// cache static
Expand All @@ -70,6 +71,9 @@ module.exports = function staticCache(options){
, contentLength = headers['content-length']
, hit;

// dont cache when cookies are present
if (hasCookies) return;

// ignore larger files
if (!contentLength || contentLength > maxlen) return;

Expand Down Expand Up @@ -117,7 +121,7 @@ module.exports = function staticCache(options){
if (req.method == 'GET' || req.method == 'HEAD') {
if (ranges) {
next();
} else if (hit && !mustRevalidate(req, hit)) {
} else if (!hasCookies && hit && !mustRevalidate(req, hit)) {
res.setHeader('X-Cache', 'HIT');
respondFromCache(req, res, hit);
} else {
Expand Down

0 comments on commit e3aa033

Please sign in to comment.