fixed compression

This commit is contained in:
2026-05-14 19:54:46 +02:00
parent 2a6a4e6483
commit 7d04b764d5
2 changed files with 12 additions and 3 deletions
+10 -1
View File
@@ -2,6 +2,13 @@ import type { APIRoute } from 'astro';
const FORBIDDEN_HEADERS = new Set([
'host', 'connection', 'content-length', 'transfer-encoding', 'origin', 'referer',
'accept-encoding',
]);
// Node fetch auto-decompresses the response body, so any encoding/length
// headers from the upstream no longer match what we forward to the browser.
const FORBIDDEN_RESPONSE_HEADERS = new Set([
'content-encoding', 'content-length', 'transfer-encoding',
]);
export const ALL: APIRoute = async ({ request, params }) => {
@@ -39,8 +46,10 @@ export const ALL: APIRoute = async ({ request, params }) => {
const responseHeaders = new Headers();
response.headers.forEach((value, key) => {
const k = key.toLowerCase();
// Set-Cookie can repeat and must NOT be merged. Handle it separately below.
if (key.toLowerCase() === 'set-cookie') return;
if (k === 'set-cookie') return;
if (FORBIDDEN_RESPONSE_HEADERS.has(k)) return;
responseHeaders.set(key, value);
});
// @ts-ignore — getSetCookie is on Node fetch's Headers