diff --git a/index.js b/index.js index 2a71924..f6f34b9 100644 --- a/index.js +++ b/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); diff --git a/test/requesttest.js b/test/requesttest.js index c14612b..e3072a3 100644 --- a/test/requesttest.js +++ b/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());