From 18ca2e90ac866a427774738a5cd7d1668c18a724 Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Thu, 16 Jan 2025 11:12:10 -0700 Subject: [PATCH] Recommended fix for CORs immutable headers issue Fixes https://github.com/kwhitley/itty-router/issues/261 by creating a new response with mutable headers and avoiding duplicating the body. The correct fix for what https://github.com/kwhitley/itty-router/commit/74f63abb25d12666e7c05e5e82fcf7432f8dbda4#diff-a1624121bc1fee18f8a5c2b2f907f01ba9c56a50068007e4c5da2911e91ea6df was trying to achieve. --- src/cors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cors.ts b/src/cors.ts index 9b08608..3349a98 100644 --- a/src/cors.ts +++ b/src/cors.ts @@ -78,7 +78,7 @@ export const cors = (options: CorsOptions = {}) => { || response.status == 101 ) return response - return appendHeadersAndReturn(response.clone(), { + return appendHeadersAndReturn(new Response(response.body, response), { 'access-control-allow-origin': getAccessControlOrigin(request), 'access-control-allow-credentials': credentials, })