fixed compression
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user