diff --git a/src/controller/index.ts b/src/controller/index.ts index c307354..0c2e9d3 100644 --- a/src/controller/index.ts +++ b/src/controller/index.ts @@ -30,7 +30,7 @@ export class ScramjetController { serviceworkers: false, naiiveRewriter: false, captureErrors: true, - strictRewrites: false, + strictRewrites: true, syncxhr: false, cleanerrors: false, scramitize: false, diff --git a/src/worker/fetch.ts b/src/worker/fetch.ts index b2c843f..d7e337c 100644 --- a/src/worker/fetch.ts +++ b/src/worker/fetch.ts @@ -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; + public response?: BareResponseFetch; +}