mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 15:40:02 -04:00
fix fetch proy
This commit is contained in:
parent
58f6a4330a
commit
f9e7fc76d9
1 changed files with 9 additions and 1 deletions
|
@ -1,11 +1,19 @@
|
||||||
// ts throws an error if you dont do window.fetch
|
// ts throws an error if you dont do window.fetch
|
||||||
|
|
||||||
|
import { ScramjetClient } from "../../client";
|
||||||
import { encodeUrl, rewriteHeaders } from "../../shared";
|
import { encodeUrl, rewriteHeaders } from "../../shared";
|
||||||
|
|
||||||
export default function (client: ScramjetClient, self: typeof globalThis) {
|
export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
client.Proxy("fetch", {
|
client.Proxy("fetch", {
|
||||||
apply(ctx) {
|
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)
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue