misc fixes

This commit is contained in:
velzie 2024-08-03 11:20:15 -04:00
parent 7e8e9990f4
commit a58f9bcb63
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
6 changed files with 26 additions and 8 deletions

View file

@ -1,5 +1,6 @@
// ts throws an error if you dont do window.fetch
import { isemulatedsw } from "../..";
import { ScramjetClient } from "../../client";
import { encodeUrl, rewriteHeaders } from "../../shared";
@ -7,8 +8,9 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
client.Proxy("fetch", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0].toString();
ctx.args[0] = encodeUrl(ctx.args[0].toString());
if (isemulatedsw) ctx.args[0] += "?from=swruntime";
}
},
});
@ -21,7 +23,11 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
client.Proxy("Request", {
construct(ctx) {
if (typeof ctx.args[0] === "string") ctx.args[0] = encodeUrl(ctx.args[0]);
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = encodeUrl(ctx.args[0].toString());
if (isemulatedsw) ctx.args[0] += "?from=swruntime";
}
},
});