fix fetch proy

This commit is contained in:
Avad3 2024-07-29 22:54:44 -04:00
parent 58f6a4330a
commit f9e7fc76d9

View file

@ -1,11 +1,19 @@
// ts throws an error if you dont do window.fetch
import { ScramjetClient } from "../../client";
import { encodeUrl, rewriteHeaders } from "../../shared";
export default function (client: ScramjetClient, self: typeof globalThis) {
client.Proxy("fetch", {
apply(ctx) {
ctx.args[0] = encodeUrl(ctx.args[0]);
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0].toString();
ctx.args[0] = encodeUrl(ctx.args[0].toString());
} else if (ctx.args[0] instanceof Request && ctx.args[0].url) {
Object.defineProperty(ctx.args[0], "url", {
value: encodeUrl(ctx.args[0].url)
});
}
},
});