mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 22:40:01 -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,
|
serviceworkers: false,
|
||||||
naiiveRewriter: false,
|
naiiveRewriter: false,
|
||||||
captureErrors: true,
|
captureErrors: true,
|
||||||
strictRewrites: false,
|
strictRewrites: true,
|
||||||
syncxhr: false,
|
syncxhr: false,
|
||||||
cleanerrors: false,
|
cleanerrors: false,
|
||||||
scramitize: false,
|
scramitize: false,
|
||||||
|
|
|
@ -139,17 +139,28 @@ export async function swfetch(
|
||||||
headers.set("Sec-Fetch-Site", "same-origin");
|
headers.set("Sec-Fetch-Site", "same-origin");
|
||||||
headers.set("Sec-Fetch-Dest", "empty");
|
headers.set("Sec-Fetch-Dest", "empty");
|
||||||
|
|
||||||
const response: BareResponseFetch = await this.client.fetch(url, {
|
const ev = new ScramjetRequestEvent("request");
|
||||||
method: request.method,
|
ev.url = url;
|
||||||
body: request.body,
|
ev.body = request.body;
|
||||||
headers: headers.headers,
|
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",
|
credentials: "omit",
|
||||||
mode: request.mode === "cors" ? request.mode : "same-origin",
|
mode: request.mode === "cors" ? request.mode : "same-origin",
|
||||||
cache: request.cache,
|
cache: request.cache,
|
||||||
redirect: "manual",
|
redirect: "manual",
|
||||||
//@ts-ignore why the fuck is this not typed mircosoft
|
//@ts-ignore why the fuck is this not typed mircosoft
|
||||||
duplex: "half",
|
duplex: "half",
|
||||||
});
|
}));
|
||||||
|
|
||||||
return await handleResponse(
|
return await handleResponse(
|
||||||
url,
|
url,
|
||||||
|
@ -310,3 +321,13 @@ export class ScramjetHandleResponseEvent extends Event {
|
||||||
public rawResponse: BareResponseFetch;
|
public rawResponse: BareResponseFetch;
|
||||||
public client: Client;
|
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