Socket
Socket
Sign inDemoInstall

http-cache-semantics

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-cache-semantics - npm Package Compare versions

Comparing version 3.3.0 to 3.3.1

12

index.js

@@ -25,2 +25,11 @@ 'use strict';

function formatCacheControl(cc) {
let parts = [];
for(const k in cc) {
const v = cc[k];
parts.push(v === true ? k : k + '=' + v);
}
return parts.join(', ');
}
module.exports = class CachePolicy {

@@ -57,5 +66,8 @@ constructor(req, res, {shared, cacheHeuristic, ignoreCargoCult, _fromObject} = {}) {

if (ignoreCargoCult && "pre-check" in this._rescc && "post-check" in this._rescc) {
delete this._rescc['pre-check'];
delete this._rescc['post-check'];
delete this._rescc['no-cache'];
delete this._rescc['no-store'];
delete this._rescc['must-revalidate'];
this._resHeaders = Object.assign({}, this._resHeaders, {'cache-control': formatCacheControl(this._rescc)});
}

@@ -62,0 +74,0 @@

2

package.json
{
"name": "http-cache-semantics",
"version": "3.3.0",
"version": "3.3.1",
"description": "Parses Cache-Control headers and friends",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -38,13 +38,28 @@ 'use strict';

it('pre-check tolerated', function() {
const cache = new CachePolicy(req, {headers:{'cache-control': 'pre-check=0, post-check=0, no-store, no-cache, max-age=100'}});
const cc = 'pre-check=0, post-check=0, no-store, no-cache, max-age=100';
const cache = new CachePolicy(req, {headers:{'cache-control': cc}});
assert(cache.stale());
assert(!cache.storable());
assert.equal(cache.maxAge(), 0);
assert.equal(cache.responseHeaders()['cache-control'], cc);
});
it('pre-check poison', function() {
const cache = new CachePolicy(req, {headers:{'cache-control': 'pre-check=0, post-check=0, no-cache, no-store, max-age=100'}}, {ignoreCargoCult:true});
const origCC = 'pre-check=0, post-check=0, no-cache, no-store, max-age=100, custom, foo=bar';
const res = {headers:{'cache-control': origCC}};
const cache = new CachePolicy(req, res, {ignoreCargoCult:true});
assert(!cache.stale());
assert(cache.storable());
assert.equal(cache.maxAge(), 100);
const cc = cache.responseHeaders()['cache-control'];
assert(!/pre-check/.test(cc), cc);
assert(!/post-check/.test(cc), cc);
assert(!/no-store/.test(cc), cc);
assert(/max-age=100/.test(cc));
assert(/custom(,|$)/.test(cc));
assert(/foo=bar/.test(cc));
assert.equal(res.headers['cache-control'], origCC);
});

@@ -51,0 +66,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with âšĄïž by Socket Inc