From 2be9c32c7e9a909d22895f514273856fae3cc724 Mon Sep 17 00:00:00 2001 From: Rizky Date: Fri, 21 Jun 2024 12:37:56 +0700 Subject: [PATCH] fix --- pkgs/core/api/_proxy.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/core/api/_proxy.ts b/pkgs/core/api/_proxy.ts index ef1a4331..9b468b39 100644 --- a/pkgs/core/api/_proxy.ts +++ b/pkgs/core/api/_proxy.ts @@ -24,11 +24,27 @@ export const _ = { headers[k] = v; }); - return await fetch(url as any, { + const res = await fetch(url as any, { method: req.method || "POST", headers, body, }); + + let res_body: any = null; + const res_headers: any = {}; + res.headers.forEach((v, k) => { + res_headers[k] = v; + }); + res_body = await res.arrayBuffer(); + if (res_headers["content-encoding"] === "gzip") { + res_body = await gzipAsync(new Uint8Array(res_body)); + delete res_headers["content-encoding"]; + } else if (res_headers["content-encoding"] === "zstd") { + res_body = await decompress(res_body); + delete res_headers["content-encoding"]; + } + + return new Response(res_body, { headers: res_headers }); } catch (e: any) { new Response( JSON.stringify({