This commit is contained in:
Rizky 2024-06-21 12:37:56 +07:00
parent d1be753ae7
commit 2be9c32c7e
1 changed files with 17 additions and 1 deletions

View File

@ -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({