Skip to content

Commit

Permalink
fix: fetch fixes, origin header
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Dec 9, 2024
1 parent 2b0fc56 commit ccefa04
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/worker/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ export async function handleFetch(
// console.log(headers);
} else {
headers.set("Referer", clientURL.toString());
headers.set("Origin", clientURL.origin);
headers.set(
"Origin",
clientURL.origin ? `${clientURL.protocol}//${clientURL.host}` : "null"
);
}
}

Expand Down Expand Up @@ -320,6 +323,8 @@ async function rewriteBody(
case "document":
if (response.headers.get("content-type")?.startsWith("text/html")) {
// note from percs: i think this has the potential to be slow asf, but for right now its fine (we should probably look for a better solution)
// another note from percs: regex seems to be broken, gonna comment this out
/*
const buf = await response.arrayBuffer();
const decode = new TextDecoder("utf-8").decode(buf);
const charsetHeader = response.headers.get("content-type");
Expand All @@ -330,8 +335,8 @@ async function rewriteBody(
const htmlContent = charset
? new TextDecoder(charset).decode(buf)
: decode;

return rewriteHtml(htmlContent, cookieStore, meta, true);
*/
return rewriteHtml(await response.text(), cookieStore, meta, true);
} else {
return response.body;
}
Expand Down

0 comments on commit ccefa04

Please sign in to comment.