Skip to content

Commit

Permalink
fix: more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Nov 17, 2024
1 parent cbdcc2a commit 9398cf7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/client/swruntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ function handleMessage(
const port = this.recvport;
const type = data.scramjet$type;
const token = data.scramjet$token;
const handlers = client.eventcallbacks.get(self);

if (type === "fetch") {
dbg.log("ee", data);
const fetchhandlers = client.eventcallbacks.get(self);
const fetchhandlers = handlers.filter((event) => event.event === "fetch");
if (!fetchhandlers) return;

for (const handler of fetchhandlers) {
if (handler.event !== "fetch") continue;

const request = data.scramjet$request;

const Request = client.natives["Request"];
Expand Down
1 change: 0 additions & 1 deletion src/shared/rewriters/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { $scramjet } from "../../scramjet";
import { rewriteJs } from "./js";
import { URLMeta } from "./url";

// const clientscripts = ["wasm", "shared", "client"];
export function rewriteWorkers(
js: string | ArrayBuffer,
type: string,
Expand Down
7 changes: 3 additions & 4 deletions src/worker/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function newmeta(url: URL): URLMeta {
};
}

export async function swfetch(
export async function handleFetch(
this: ScramjetServiceWorker,
request: Request,
client: Client | null
Expand Down Expand Up @@ -137,14 +137,13 @@ export async function swfetch(
}

headers.set("Sec-Fetch-Dest", request.destination);
//TODO: Emulate this later (like really)
headers.set("Sec-Fetch-Site", "same-origin");
headers.set(
"Sec-Fetch-Mode",
request.mode === "cors" ? request.mode : "same-origin"
);

//TODO: Emulate this later
//headers.set("Sec-Fetch-Site", "same-origin");

const ev = new ScramjetRequestEvent(
url,
request.body,
Expand Down
4 changes: 2 additions & 2 deletions src/worker/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FakeServiceWorker } from "./fakesw";
import { swfetch } from "./fetch";
import { handleFetch } from "./fetch";
import type BareClient from "@mercuryworkshop/bare-mux";
import { ScramjetConfig } from "../types";
import { $scramjet, loadCodecs } from "../scramjet";
Expand Down Expand Up @@ -90,7 +90,7 @@ export class ScramjetServiceWorker extends EventTarget {
async fetch({ request, clientId }: FetchEvent) {
const client = await self.clients.get(clientId);

return swfetch.call(this, request, client);
return handleFetch.call(this, request, client);
}
}

Expand Down

0 comments on commit 9398cf7

Please sign in to comment.