Skip to content

fix(proxy): preserve binary request bodies and forward DELETE/OPTIONS bodies (#157) - #159

Open
Baddevil512 wants to merge 1 commit into
tscircuit:mainfrom
Baddevil512:fix/proxy-binary-and-delete-body-157
Open

Baddevil512 wants to merge 1 commit into
tscircuit:mainfrom
Baddevil512:fix/proxy-binary-and-delete-body-157

Conversation

@Baddevil512

Copy link
Copy Markdown

/claim #157
Closes #157

Problem

/proxy previously decoded request bodies as UTF-8 text (req.clone().text()), corrupting binary payloads by replacing invalid UTF-8 sequences with replacement bytes (0xef 0xbf 0xbd). In addition, DELETE and OPTIONS request bodies were dropped.

Fix

  1. Updated routes/proxy.ts to extract request bodies as raw ArrayBuffer (await req.clone().arrayBuffer()) for all HTTP methods except GET and HEAD when rawBody.byteLength > 0.
  2. Added regression tests in tests/routes/proxy-binary-body.test.ts verifying byte-for-byte binary payload preservation (Uint8Array([0x00, 0xff, 0xfe, 0x80, 0x41])) across POST, PUT, PATCH, DELETE, and OPTIONS requests while keeping empty OPTIONS preflights clean.

Verification

  • bun test: 34 pass, 0 fail (180 expect() calls)
  • bunx tsc --noEmit: 0 errors
  • bun biome format: 0 errors

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.

Proxy corrupts binary request bodies and drops DELETE/OPTIONS bodies (tested fix)

2 participants