From 9a15c2ac5cb649174ac68f94edd59d8986a9f433 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sat, 10 May 2025 16:12:54 +0200 Subject: [PATCH 1/2] fix: prevent hit origin servers It seems `must-revalidate` is telling to CloudFlare to still reach origin servers, dropping it in favour of `immutable`. --- src/util.js | 2 +- test/stale-ttl.js | 4 ++-- test/ttl.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util.js b/src/util.js index f5cdf34..f4acbe9 100644 --- a/src/util.js +++ b/src/util.js @@ -64,7 +64,7 @@ const setHeaders = ({ const maxAge = toSeconds(diff) const revalidation = staleTtl ? toSeconds(staleTtl) : 0 - let cacheControl = `public, must-revalidate, max-age=${maxAge}` + let cacheControl = `public, immutable, max-age=${maxAge}` if (revalidation) { cacheControl = `${cacheControl}, stale-while-revalidate=${revalidation}, stale-if-error=${revalidation}` diff --git a/test/stale-ttl.js b/test/stale-ttl.js index ed27e7a..a2859aa 100644 --- a/test/stale-ttl.js +++ b/test/stale-ttl.js @@ -19,7 +19,7 @@ test('enabled by default', async t => { const { headers } = await got(`${url}/kikobeats`) const cacheControl = parseCacheControl(headers) t.true(cacheControl.public) - t.true(cacheControl['must-revalidate']) + t.true(cacheControl.immutable) t.true([86399, 86400].includes(cacheControl['max-age'])) t.true([3600, 3599].includes(cacheControl['stale-while-revalidate'])) t.true([3600, 3599].includes(cacheControl['stale-if-error'])) @@ -39,7 +39,7 @@ test('as value', async t => { const { headers } = await got(`${url}/kikobeats`) const cacheControl = parseCacheControl(headers) t.true(cacheControl.public) - t.true(cacheControl['must-revalidate']) + t.true(cacheControl.immutable) t.true([86399, 86400].includes(cacheControl['max-age'])) t.true([299, 300].includes(cacheControl['stale-while-revalidate'])) t.true([299, 300].includes(cacheControl['stale-if-error'])) diff --git a/test/ttl.js b/test/ttl.js index 8d698a0..a382f81 100644 --- a/test/ttl.js +++ b/test/ttl.js @@ -21,7 +21,7 @@ test('as value', async t => { const { headers } = await got(`${url}/kikobeats`) const cacheControl = parseCacheControl(headers) t.true(cacheControl.public) - t.true(cacheControl['must-revalidate']) + t.true(cacheControl.immutable) t.true([3600, 3599].includes(cacheControl['max-age'])) t.true([720, 719].includes(cacheControl['stale-while-revalidate'])) t.true([720, 719].includes(cacheControl['stale-if-error'])) @@ -41,7 +41,7 @@ test('from value', async t => { const { headers } = await got(`${url}/kikobeats`) const cacheControl = parseCacheControl(headers) t.true(cacheControl.public) - t.true(cacheControl['must-revalidate']) + t.true(cacheControl.immutable) t.true([86399, 86400].includes(cacheControl['max-age'])) t.true([17279, 17280].includes(cacheControl['stale-while-revalidate'])) t.true([17279, 17280].includes(cacheControl['stale-if-error'])) @@ -60,6 +60,6 @@ test('sets default ttl', async t => { const { headers } = await got(`${url}/kikobeats`) const cacheControl = parseCacheControl(headers) t.true(cacheControl.public) - t.true(cacheControl['must-revalidate']) + t.true(cacheControl.immutable) t.true([86400, 86399].includes(cacheControl['max-age'])) }) From 28a54bbbaee84daf3cad8d1227fa518e266678bf Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Sat, 10 May 2025 16:14:17 +0200 Subject: [PATCH 2/2] chore(release): 2.11.0-0 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c71faf..e8213da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [2.11.0-0](https://github.com/Kikobeats/cacheable-response/compare/v2.10.3...v2.11.0-0) (2025-05-10) + + +### Bug Fixes + +* prevent hit origin servers ([9a15c2a](https://github.com/Kikobeats/cacheable-response/commit/9a15c2ac5cb649174ac68f94edd59d8986a9f433)) + ### 2.10.3 (2025-05-10) ### 2.10.2 (2024-05-09) diff --git a/package.json b/package.json index 340ab7d..017b32a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "cacheable-response", "description": "An HTTP compliant route path middleware for serving cache response with invalidation support.", "homepage": "https://github.com/Kikobeats/cacheable-response", - "version": "2.10.3", + "version": "2.11.0-0", "main": "src/index.js", "author": { "email": "josefrancisco.verdu@gmail.com",