Skip to content

Commit

Permalink
fixup! fix: ensure that the Pages dev proxy server does not change th…
Browse files Browse the repository at this point in the history
…e Host header
  • Loading branch information
petebacondarwin committed Feb 2, 2024
1 parent 61dadd4 commit 7061e33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 2 additions & 0 deletions fixtures/pages-proxy-app/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe("pages-proxy-app", async () => {
stdio: "ignore",
});

debugger;
({ ip, port, stop } = await runWranglerPagesDev(
resolve(__dirname, ".."),
undefined,
Expand All @@ -27,6 +28,7 @@ describe("pages-proxy-app", async () => {
});

it("receives the correct Host header", async ({ expect }) => {
debugger;
const response = await fetch(`http://${ip}:${port}/`);
const text = await response.text();
expect(text).toContain(`Host:${ip}:${port}`);
Expand Down
25 changes: 9 additions & 16 deletions packages/wrangler/src/miniflare-cli/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,15 @@ class ProxyDispatcher extends Dispatcher {
host: string
) {
assert(headers, "Expected all proxy requests to contain headers.");
if (Array.isArray(headers)) {
assert(
headers.every(
// Note that `headers` is a flat array of key-value pairs so we only check the even items.
(h, index) => index % 2 === 1 || h.toLowerCase() !== "host",
"Expected Host header to have been deleted."
)
);
headers.push("Host", host);
} else {
assert(
Object.keys(headers).every((h) => h.toLowerCase() !== "host"),
"Expected Host header to have been deleted."
);
headers["Host"] = host;
}
assert(
!Array.isArray(headers),
"Expected proxy request headers to be a hash object"
);
assert(
Object.keys(headers).every((h) => h.toLowerCase() !== "host"),
"Expected Host header to have been deleted."
);
headers["Host"] = host;
}
}

Expand Down

0 comments on commit 7061e33

Please sign in to comment.