Skip to content

fix: forward POST body and content-type header#7

Merged
jergason merged 1 commit intomainfrom
fix/forward-post-body
Mar 23, 2026
Merged

fix: forward POST body and content-type header#7
jergason merged 1 commit intomainfrom
fix/forward-post-body

Conversation

@jergason
Copy link
Copy Markdown
Owner

Summary

  • Bug: form submissions were completely broken — the request body was dropped and the Content-Type header wasn't forwarded. Every search form, login form, and comment form was sending empty POST requests to the target.
  • Forward request.body for non-GET/HEAD methods
  • Add content-type to the forwarded headers list in forwardHeaders()
  • Verified via httpbin.org/post: form data {query: "test", page: "1"} now arrives correctly

Test plan

  • 35 tests pass (including new POST body forwarding test via httpbin)
  • All checks clean: lint, format, types, knip
  • GET requests still work (httpbin, Wikipedia, HN)
  • Wikipedia search redirect works through proxy

🤖 Generated with Claude Code

form submissions were completely broken — the request body was not
forwarded to the target, and the content-type header was missing from
the forwarded headers list. every search form, login form, and comment
form on the internet was sending empty POST requests.

fixes:
- forward request.body for non-GET/HEAD requests
- add content-type to the forwarded headers list

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 23, 2026 19:06
@jergason jergason merged commit 6f13e4c into main Mar 23, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes proxying of form submissions by ensuring non-GET/HEAD requests forward their body and Content-Type, so upstream servers can correctly parse submitted data.

Changes:

  • Forward request bodies for non-GET/HEAD methods in the proxy fetch call.
  • Include content-type in the allowlist of forwarded request headers.
  • Add an integration test that validates POST form data reaches the upstream.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/proxy.ts Forwards request body to the upstream fetch for non-GET/HEAD methods.
src/utils.ts Allows content-type to be forwarded to upstream requests.
src/rewriter.test.ts Adds an integration test intended to verify POST body + Content-Type forwarding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/rewriter.test.ts
Comment on lines +142 to +148
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;
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants