mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
scramjetRequestEvent
This commit is contained in:
parent
3ece6a555e
commit
883d8fb4a9
2 changed files with 33 additions and 12 deletions
|
@ -30,7 +30,7 @@ export class ScramjetController {
|
|||
serviceworkers: false,
|
||||
naiiveRewriter: false,
|
||||
captureErrors: true,
|
||||
strictRewrites: false,
|
||||
strictRewrites: true,
|
||||
syncxhr: false,
|
||||
cleanerrors: false,
|
||||
scramitize: false,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue