Skip to content

Commit

Permalink
fix: requests suck
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Nov 18, 2024
1 parent 7b0769c commit 8b8c9b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@types/eslint": "^9.6.1",
"@types/estree": "^1.0.6",
"@types/node": "^22.9.0",
"@types/serviceworker": "^0.0.102",
"@types/serviceworker": "^0.0.103",
"@typescript-eslint/eslint-plugin": "^8.13.0",
"@typescript-eslint/parser": "^8.13.0",
"dotenv": "^16.4.5",
Expand All @@ -57,7 +57,7 @@
"wisp-server-node": "^1.1.7"
},
"dependencies": {
"@mercuryworkshop/bare-mux": "^2.1.6",
"@mercuryworkshop/bare-mux": "^2.1.7",
"dom-serializer": "^2.0.0",
"domhandler": "^5.0.3",
"domutils": "^3.1.0",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions src/worker/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ export async function handleFetch(
method: ev.method,
body: ev.body,
headers: ev.requestHeaders,
//@ts-expect-error no types
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",
}));

Expand Down Expand Up @@ -304,7 +308,7 @@ async function handleResponse(
}

async function rewriteBody(
response: Response,
response: BareResponseFetch,
meta: URLMeta,
destination: RequestDestination,
workertype: string,
Expand All @@ -319,15 +323,15 @@ async function rewriteBody(
return response.body;
}
case "script":
return rewriteJs(await response.arrayBuffer(), response.url, meta);
return rewriteJs(await response.arrayBuffer(), response.finalURL, meta);
case "style":
return rewriteCss(await response.text(), meta);
case "sharedworker":
case "worker":
return rewriteWorkers(
await response.arrayBuffer(),
workertype,
response.url,
response.finalURL,
meta
);
default:
Expand Down
2 changes: 1 addition & 1 deletion static/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ scramjet.addEventListener("request", (e) => {
}
if (playgroundData) {
e.response.rawHeaders = headers;
e.response.finalURL = e.url;
e.response.finalURL = e.url.toString();
}
});

0 comments on commit 8b8c9b4

Please sign in to comment.