From 1e0e09ba59c7eab74cf1d09819272c1097028694 Mon Sep 17 00:00:00 2001 From: dktsudgg Date: Tue, 28 Jul 2026 03:52:56 +0900 Subject: [PATCH] Avoid duplicate response headers on Elysia 1.4.18 and earlier When a response has a body, the plugin returns the `response` object directly, so there is no need to copy the response's headers into Elysia's `set.headers`. Elysia already includes `response.headers` in the HTTP response on its own. In fact, on Elysia 1.4.18 and earlier, copying `response.headers` into `set.headers` and then returning the response causes the HTTP response headers to be duplicated. (This was fixed on Elysia's side in 1.4.19.) This change therefore moves the early return of the `response` object, for the case where a body exists, above the header copy so that the HTTP response headers are no longer duplicated. While this problem is partly due to the bug in Elysia 1.4.18 and earlier, this fix is expected to resolve it sufficiently, so it does not raise the project's minimum Elysia version, keeping the current Elysia version support range intact. Assisted-by: Claude Code:claude-fable-5 --- packages/elysia/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/elysia/src/index.ts b/packages/elysia/src/index.ts index 8a1648abb..9381d0d13 100644 --- a/packages/elysia/src/index.ts +++ b/packages/elysia/src/index.ts @@ -42,15 +42,15 @@ export const fedify = ( if (!notFound && !notAcceptable) { set.status = response.status; - response.headers.forEach((value, key) => { - set.headers[key] = value; - }); - // Return response body if it exists if (response.body) { return response; } + response.headers.forEach((value, key) => { + set.headers[key] = value; + }); + // Return empty response for successful requests without body return new Response(null, { status: response.status }); }