Skip to content

Commit a309d1c

Browse files
authored
only cache response if response has cache-control header (#9885)
* only cache response if response has cache-control header * add changeset
1 parent b3539c5 commit a309d1c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

.changeset/tidy-worms-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-cloudflare': patch
3+
---
4+
5+
fix: require explicit cache-control header for caching

packages/adapter-cloudflare/src/worker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const worker = {
5555

5656
// write to `Cache` only if response is not an error,
5757
// let `Cache.save` handle the Cache-Control and Vary headers
58-
return res.status >= 400 ? res : Cache.save(req, res, context);
58+
pragma = res.headers.get('cache-control') || '';
59+
return pragma && res.status < 400 ? Cache.save(req, res, context) : res;
5960
}
6061
};
6162

0 commit comments

Comments
 (0)