Skip to content

Commit

Permalink
🐛 fix immutable header mutation in handleThumbnailRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Jan 17, 2025
1 parent 67d9b94 commit 5068d5e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion functions/_common/reusableHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ export async function handleThumbnailRequest(

const cache = caches.default
console.log("Handling", env.url, ctx.request.headers.get("User-Agent"))

if (shouldCache) {
console.log("Checking cache")
const maybeCached = await cache.match(ctx.request)
console.log("Cache check result", maybeCached ? "hit" : "miss")
if (maybeCached) return maybeCached
if (maybeCached) {
// Cached responses are immutable, so we have to clone them,
// so that the corsify middleware can add CORS headers
const newResponse = new Response(maybeCached.body, maybeCached)
return newResponse
}
}

const resp = await fetchAndRenderGrapher(id, searchParams, extension, env)
if (shouldCache) {
resp.headers.set("Cache-Control", "s-maxage=3600, max-age=3600")
Expand Down

0 comments on commit 5068d5e

Please sign in to comment.