scramjetRequestEvent

This commit is contained in:
velzie 2024-10-24 15:11:27 -04:00
parent 3ece6a555e
commit 883d8fb4a9
No known key found for this signature in database
GPG key ID: AA51AEFB0A1F3820
2 changed files with 33 additions and 12 deletions

View file

@ -30,7 +30,7 @@ export class ScramjetController {
serviceworkers: false,
naiiveRewriter: false,
captureErrors: true,
strictRewrites: false,
strictRewrites: true,
syncxhr: false,
cleanerrors: false,
scramitize: false,

View file

@ -139,17 +139,28 @@ export async function swfetch(
headers.set("Sec-Fetch-Site", "same-origin");
headers.set("Sec-Fetch-Dest", "empty");
const response: BareResponseFetch = await this.client.fetch(url, {
method: request.method,
body: request.body,
headers: headers.headers,
credentials: "omit",
mode: request.mode === "cors" ? request.mode : "same-origin",
cache: request.cache,
redirect: "manual",
//@ts-ignore why the fuck is this not typed mircosoft
duplex: "half",
});
const ev = new ScramjetRequestEvent("request");
ev.url = url;
ev.body = request.body;
ev.method = request.method;
ev.destination = request.destination;
ev.client = client;
ev.requestHeaders = headers.headers;
this.dispatchEvent(ev);
const response: BareResponseFetch =
ev.response ||
(await this.client.fetch(ev.url, {
method: ev.method,
body: ev.body,
headers: ev.requestHeaders,
credentials: "omit",
mode: request.mode === "cors" ? request.mode : "same-origin",
cache: request.cache,
redirect: "manual",
//@ts-ignore why the fuck is this not typed mircosoft
duplex: "half",
}));
return await handleResponse(
url,
@ -310,3 +321,13 @@ export class ScramjetHandleResponseEvent extends Event {
public rawResponse: BareResponseFetch;
public client: Client;
}
export class ScramjetRequestEvent extends Event {
public url: URL;
public destination: string;
public client: Client;
public method: string;
public body: BodyType;
public requestHeaders: Record<string, string>;
public response?: BareResponseFetch;
}