Browse Source

Nuke lame expires too

master v3.3.3
Kornel Lesiński 8 years ago
parent
commit
c9fe4786a6
  1. 4
      index.js
  2. 2
      package.json
  3. 15
      test/responsetest.js

4
index.js

@ -28,6 +28,9 @@ function formatCacheControl(cc) {
const v = cc[k];
parts.push(v === true ? k : k + '=' + v);
}
if (!parts.length) {
return undefined;
}
return parts.join(', ');
}
@ -68,6 +71,7 @@ module.exports = class CachePolicy {
delete this._rescc['no-store'];
delete this._rescc['must-revalidate'];
this._resHeaders = Object.assign({}, this._resHeaders, {'cache-control': formatCacheControl(this._rescc)});
delete this._resHeaders['expires'];
delete this._resHeaders['pragma'];
}

2
package.json

@ -1,6 +1,6 @@
{
"name": "http-cache-semantics",
"version": "3.3.2",
"version": "3.3.3",
"description": "Parses Cache-Control headers and friends",
"main": "index.js",
"repository": "https://github.com/pornel/http-cache-semantics.git",

15
test/responsetest.js

@ -65,6 +65,21 @@ describe('Response headers', function() {
assert(!cache.responseHeaders()['pragma']);
});
it('pre-check poison undefined header', function() {
const origCC = 'pre-check=0, post-check=0, no-cache, no-store';
const res = {headers:{'cache-control': origCC, expires: 'yesterday!'}};
const cache = new CachePolicy(req, res, {ignoreCargoCult:true});
assert(cache.stale());
assert(cache.storable());
assert.equal(cache.maxAge(), 0);
const cc = cache.responseHeaders()['cache-control'];
assert(!cc);
assert(res.headers['expires']);
assert(!cache.responseHeaders()['expires']);
});
it('cache with expires', function() {
const cache = new CachePolicy(req, {headers:{
'date': new Date().toGMTString(),

Loading…
Cancel
Save