summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/src/ssr-function.ts
diff options
context:
space:
mode:
authorGravatar Simon Knott <info@simonknott.de> 2024-01-11 12:56:25 +0100
committerGravatar GitHub <noreply@github.com> 2024-01-11 12:56:25 +0100
commit9dbd6832d59a88e9b2d992f308d7c325c269b956 (patch)
tree355c5d2ccc716499ad223069a911e331bef5f349 /packages/integrations/netlify/src/ssr-function.ts
parent1d3884c20c2806e5bd7890721726351596280073 (diff)
downloadastro-9dbd6832d59a88e9b2d992f308d7c325c269b956.tar.gz
astro-9dbd6832d59a88e9b2d992f308d7c325c269b956.tar.zst
astro-9dbd6832d59a88e9b2d992f308d7c325c269b956.zip
fix(netlify): only cache GET/HEAD methods (#127)
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Diffstat (limited to 'packages/integrations/netlify/src/ssr-function.ts')
-rw-r--r--packages/integrations/netlify/src/ssr-function.ts4
1 files changed, 3 insertions, 1 deletions
diff --git a/packages/integrations/netlify/src/ssr-function.ts b/packages/integrations/netlify/src/ssr-function.ts
index 7cf5ea227..42c3d1952 100644
--- a/packages/integrations/netlify/src/ssr-function.ts
+++ b/packages/integrations/netlify/src/ssr-function.ts
@@ -36,6 +36,8 @@ export const createExports = (manifest: SSRManifest, _args: Args) => {
}
if (integrationConfig.cacheOnDemandPages) {
+ const isCacheableMethod = ['GET', 'HEAD'].includes(request.method);
+
// any user-provided Cache-Control headers take precedence
const hasCacheControl = [
'Cache-Control',
@@ -43,7 +45,7 @@ export const createExports = (manifest: SSRManifest, _args: Args) => {
'Netlify-CDN-Cache-Control',
].some((header) => response.headers.has(header));
- if (!hasCacheControl) {
+ if (isCacheableMethod && !hasCacheControl) {
// caches this page for up to a year
response.headers.append('CDN-Cache-Control', 'public, max-age=31536000, must-revalidate');
}