Browse Source

Fixed proxy validation

master
Kornel Lesiński 9 years ago
parent
commit
b5d2edf9f7
  1. 7
      index.js
  2. 17
      test/requesttest.js

7
index.js

@ -17,10 +17,6 @@ function parseCacheControl(header) {
cc[k] = (v === undefined) ? true : v.replace(/^"|"$/g, ''); // TODO: lame unquoting
}
// The s-maxage directive also implies the semantics of the proxy-revalidate response directive.
if ('s-maxage' in cc) {
cc['proxy-revalidate'] = true;
}
return cc;
}
@ -181,6 +177,9 @@ CachePolicy.prototype = {
}
if (this._isShared) {
if (this._rescc['proxy-revalidate']) {
return 0;
}
// if a response includes the s-maxage directive, a shared cache recipient MUST ignore the Expires field.
if (this._rescc['s-maxage']) {
return parseInt(this._rescc['s-maxage'], 10);

17
test/requesttest.js

@ -31,6 +31,23 @@ describe('Request properties', function() {
assert(cache.storable());
});
it('Proxy cacheable auth is OK', function() {
const cache = new CachePolicy({method:'GET',headers:{'authorization': 'test'}}, {headers:{'cache-control':'max-age=0,s-maxage=12'}});
assert(!cache.stale());
assert(cache.storable());
});
it('Private auth is OK', function() {
const cache = new CachePolicy({method:'GET',headers:{'authorization': 'test'}}, cacheableResponse, {shared:false});
assert(!cache.stale());
assert(cache.storable());
});
it('Revalidated auth is OK', function() {
const cache = new CachePolicy({headers:{'authorization': 'test'}}, {headers:{'cache-control':'max-age=88,must-revalidate'}});
assert(cache.storable());
});
it('Auth prevents caching by default', function() {
const cache = new CachePolicy({method:'GET',headers:{'authorization': 'test'}}, cacheableResponse);
assert(cache.stale());

Loading…
Cancel
Save