support url base

This commit is contained in:
velzie 2024-09-01 13:26:24 -04:00
parent a1ce4e33b3
commit 7a9c990b01
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
32 changed files with 213 additions and 158 deletions

View file

@ -1,16 +1,17 @@
import { decodeUrl, encodeUrl, rewriteHeaders } from "../../../shared";
import { ScramjetClient } from "../../client";
export default function (client, self) {
export default function (client: ScramjetClient, self: Self) {
client.Proxy("XMLHttpRequest.prototype.open", {
apply(ctx) {
if (ctx.args[1]) ctx.args[1] = encodeUrl(ctx.args[1]);
if (ctx.args[1]) ctx.args[1] = encodeUrl(ctx.args[1], client.meta);
},
});
client.Proxy("XMLHttpRequest.prototype.setRequestHeader", {
apply(ctx) {
let headerObject = Object.fromEntries([ctx.args]);
headerObject = rewriteHeaders(headerObject);
headerObject = rewriteHeaders(headerObject, client.meta);
ctx.args = Object.entries(headerObject)[0];
},
@ -18,7 +19,7 @@ export default function (client, self) {
client.Trap("XMLHttpRequest.prototype.responseURL", {
get(ctx) {
return decodeUrl(ctx.get());
return decodeUrl(ctx.get() as string);
},
});
}