Skip to content

Commit

Permalink
Add check for set-cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwalshuk committed Mar 24, 2022
1 parent 37da9e4 commit 3722b93
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/adapter-cloudflare/files/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default {

// dynamically-generated pages
try {
// @ts-ignore
// `default` cache property exists in the cloudflare workers environment only.
// @ts-expect-error
const cache = caches.default;
let response = await cache.match(req);

Expand All @@ -62,9 +63,15 @@ export default {
}
});

// Use context so you can return the response without blocking on
// Use waitUntil so you can return the response without blocking on
// writing to cache
try {
// If cookies are being set, ensure we dont cache the page.
if (response.headers.has('Set-Cookie')) {
response = new Response(response.body, response);
response.headers.append('Cache-Control', 'private=Set-Cookie');
}

context.waitUntil(cache.put(req, response.clone()));
} catch {
// noop
Expand Down

0 comments on commit 3722b93

Please sign in to comment.