diff --git a/pkgs/core/api/_proxy.ts b/pkgs/core/api/_proxy.ts index fb34bd73..8fa523f0 100644 --- a/pkgs/core/api/_proxy.ts +++ b/pkgs/core/api/_proxy.ts @@ -1,5 +1,6 @@ import brotliPromise from "brotli-wasm"; import { apiContext } from "service-srv"; +import { gzipAsync } from "utils/diff/diff"; const brotli = await brotliPromise; @@ -23,11 +24,24 @@ export const _ = { headers[k] = v; }); - return await fetch(url, { + const res = await fetch(url, { 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)); + } else { + delete res_headers["content-encoding"]; + } + return new Response(res_body, { headers: res_headers }); } catch (e: any) { console.error(e); new Response(