Skip to content

Commit

Permalink
Re-order loops
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Feb 19, 2024
1 parent e9ef80d commit a99be39
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/wrangler/templates/startDevWorker/ProxyWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,25 +306,24 @@ function insertLiveReloadScript(
function rewriteUrlRelatedHeaders(headers: Headers, from: URL, to: URL) {
const setCookie = headers.getAll("Set-Cookie");
headers.delete("Set-Cookie");
for (const cookie of setCookie) {
headers.append(
"Set-Cookie",
cookie.replace(
new RegExp(`Domain=${from.hostname}($|;|,)`),
`Domain=${to.hostname}$1`
)
);
}
headers.forEach((value, key) => {
if (
typeof value === "string" &&
value.includes(from.host) &&
key !== "set-cookie"
value.includes(from.host)
) {
headers.set(
key,
value.replaceAll(from.origin, to.origin).replaceAll(from.host, to.host)
);
}
});
for (const cookie of setCookie) {
headers.append(
"Set-Cookie",
cookie.replace(
new RegExp(`Domain=${from.hostname}($|;|,)`),
`Domain=${to.hostname}$1`
)
);
}
}

0 comments on commit a99be39

Please sign in to comment.