mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-17 08:00:02 -04:00
support url base
This commit is contained in:
parent
a1ce4e33b3
commit
7a9c990b01
32 changed files with 213 additions and 158 deletions
|
@ -9,7 +9,7 @@ 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] = encodeUrl(ctx.args[0].toString());
|
||||
ctx.args[0] = encodeUrl(ctx.args[0].toString(), client.meta);
|
||||
|
||||
if (isemulatedsw) ctx.args[0] += "?from=swruntime";
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
|||
client.Proxy("Request", {
|
||||
construct(ctx) {
|
||||
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||
ctx.args[0] = encodeUrl(ctx.args[0].toString());
|
||||
ctx.args[0] = encodeUrl(ctx.args[0].toString(), client.meta);
|
||||
|
||||
if (isemulatedsw) ctx.args[0] += "?from=swruntime";
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue