From 747c6777ceea1ea11eda432c31b25c9bbfcd39b6 Mon Sep 17 00:00:00 2001 From: Rob Hanlon Date: Sat, 9 Feb 2019 11:20:06 -0800 Subject: [PATCH] Ignore Pragma when Cache-Control is present but blank --- index.js | 2 +- test/responsetest.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 47981ad..0cbcc27 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,7 @@ module.exports = class CachePolicy { // When the Cache-Control header field is not present in a request, caches MUST consider the no-cache request pragma-directive // as having the same effect as if "Cache-Control: no-cache" were present (see Section 5.2.1). - if (!res.headers['cache-control'] && /no-cache/.test(res.headers.pragma)) { + if (res.headers['cache-control'] == null && /no-cache/.test(res.headers.pragma)) { this._rescc['no-cache'] = true; } } diff --git a/test/responsetest.js b/test/responsetest.js index f15b2a6..621e105 100644 --- a/test/responsetest.js +++ b/test/responsetest.js @@ -223,6 +223,15 @@ describe('Response headers', function() { assert(cache.stale()); }); + it('blank cache-control and pragma: no-cache', function() { + const cache = new CachePolicy(req, {headers:{ + 'cache-control': '', + 'pragma': 'no-cache', + 'last-modified': new Date().toGMTString(), + }}); + assert(!cache.stale()); + }); + it('no-store', function() { const cache = new CachePolicy(req, {headers:{ 'cache-control': 'no-store, public, max-age=1',