From cd33a1548fa2d1ad5e714d976b679915d5ec58e1 Mon Sep 17 00:00:00 2001 From: fdumont Date: Tue, 9 May 2023 20:38:04 +0200 Subject: [PATCH 1/2] only cache response if response has cache-control header --- packages/adapter-cloudflare/src/worker.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare/src/worker.js b/packages/adapter-cloudflare/src/worker.js index dcdcb9a46efb..6a421a4e9ba9 100644 --- a/packages/adapter-cloudflare/src/worker.js +++ b/packages/adapter-cloudflare/src/worker.js @@ -55,7 +55,8 @@ const worker = { // write to `Cache` only if response is not an error, // let `Cache.save` handle the Cache-Control and Vary headers - return res.status >= 400 ? res : Cache.save(req, res, context); + pragma = res.headers.get('cache-control') || ''; + return pragma && res.status < 400 ? Cache.save(req, res, context) : res; } }; From 363fff03fa0601193485994b2fa07b1793c8c93d Mon Sep 17 00:00:00 2001 From: fdumont Date: Tue, 9 May 2023 20:42:50 +0200 Subject: [PATCH 2/2] add changeset --- .changeset/tidy-worms-reflect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tidy-worms-reflect.md diff --git a/.changeset/tidy-worms-reflect.md b/.changeset/tidy-worms-reflect.md new file mode 100644 index 000000000000..f7d62b156e51 --- /dev/null +++ b/.changeset/tidy-worms-reflect.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-cloudflare': patch +--- + +fix: require explicit cache-control header for caching