The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | // Alchemy modifications are licensed under Apache-2.0. |
| 2 | // This file includes third-party code; see /THIRD_PARTY_LICENSES.md. |
| 3 | // Vendored from `@astrojs/cloudflare` v14.4.2 (`src/utils/response.ts`). |
| 4 | export function applyCloudflareResponseHeaders( |
| 5 | response: Response, |
| 6 | setCookieHeaders: Iterable<string>, |
| 7 | cacheProviderEnabled: boolean, |
| 8 | ): Response { |
| 9 | const cookies = [...setCookieHeaders]; |
| 10 | // Cloudflare's Worker cache otherwise caches all GET responses for up to |
| 11 | // two hours when a route does not declare cache intent. |
| 12 | const needsNoStoreDefault = |
| 13 | cacheProviderEnabled && !response.headers.has("Cloudflare-CDN-Cache-Control"); |
| 14 | |
| 15 | if (cookies.length > 0 || needsNoStoreDefault) { |
| 16 | const applyHeaders = (target: Response) => { |
| 17 | for (const cookie of cookies) { |
| 18 | target.headers.append("Set-Cookie", cookie); |
| 19 | } |
| 20 | if (needsNoStoreDefault) { |
| 21 | target.headers.set("Cloudflare-CDN-Cache-Control", "no-store"); |
| 22 | } |
| 23 | }; |
| 24 | try { |
| 25 | applyHeaders(response); |
| 26 | } catch { |
| 27 | // Responses served from the Workers Cache API have immutable headers. The |
| 28 | // first mutation throws before changing anything, so reapplying is safe. |
| 29 | response = new Response(response.body, response); |
| 30 | applyHeaders(response); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return response; |
| 35 | } |