Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ export async function handleProxy(targetUrl: string, request: Request): Promise<

let targetResponse: Response;
try {
const hasBody = request.method !== "GET" && request.method !== "HEAD";
targetResponse = await fetch(targetUrl, {
method: request.method,
headers: forwardHeaders(request),
body: hasBody ? request.body : undefined,
redirect: "manual",
});
} catch {
Expand Down
16 changes: 16 additions & 0 deletions src/rewriter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,20 @@ describe("HTMLRewriter integration", () => {
const allProxied = dataSrcMatches.every((m) => m.includes("/browse/"));
expect(allProxied).toBe(true);
});

it("forwards POST body and content-type header", async () => {
const resp = await worker.fetch("/browse/https://httpbin.org/post", {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body: "query=test&page=1",
});
if (resp.status !== 200) return;
Comment on lines +142 to +148
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test silently passes when httpbin is unavailable (if (resp.status !== 200) return;), which means CI can go green without actually validating POST body/header forwarding. Prefer making the test deterministic (mock the upstream / use a local stub), or at least mark it as explicitly skipped (e.g., Vitest it.runIf(...) / this.skip()) rather than returning early so the missing coverage is visible.

Copilot uses AI. Check for mistakes.
const data = (await resp.json()) as {
form: Record<string, string>;
headers: Record<string, string>;
};
expect(data.form.query).toBe("test");
expect(data.form.page).toBe("1");
expect(data.headers["Content-Type"]).toContain("application/x-www-form-urlencoded");
});
});
10 changes: 9 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ export function stripHeaders(headers: Headers): Headers {

export function forwardHeaders(request: Request): HeadersInit {
const forwarded: Record<string, string> = {};
const pass = ["user-agent", "accept", "accept-language", "accept-encoding", "cookie", "referer"];
const pass = [
"user-agent",
"accept",
"accept-language",
"accept-encoding",
"cookie",
"referer",
"content-type",
];
pass.forEach((h) => {
const v = request.headers.get(h);
if (v) forwarded[h] = v;
Expand Down
Loading