Skip to content

Commit

Permalink
only cache response if response has cache-control header (#9885)
Browse files Browse the repository at this point in the history
* only cache response if response has cache-control header

* add changeset
  • Loading branch information
psytrx authored May 17, 2023
1 parent b3539c5 commit a309d1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tidy-worms-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare': patch
---

fix: require explicit cache-control header for caching
3 changes: 2 additions & 1 deletion packages/adapter-cloudflare/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down

0 comments on commit a309d1c

Please sign in to comment.