Skip to content

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

Open
Longo125 wants to merge 1 commit into
tscircuit:mainfrom
Longo125:fix/proxy-binary-and-options-bodies
Open

Longo125 wants to merge 1 commit into
tscircuit:mainfrom
Longo125:fix/proxy-binary-and-options-bodies

Conversation

@Longo125

@Longo125 Longo125 commented Oct 8, 2026

Copy link
Copy Markdown

Summary

Fixes #157.

In /proxy, requests were previously read using await req.clone().text(), which converts raw request bytes to a UTF-8 string. When proxying binary payloads (such as octet-streams, images, or compressed data), invalid UTF-8 sequences were corrupted during string decoding. Furthermore, request bodies were only read for POST, PUT, and PATCH, completely dropping bodies for DELETE and OPTIONS requests despite the route accepting those methods.

Changes

  1. Preserve binary bytes (routes/proxy.ts):
    • Switched from .text() to await req.clone().arrayBuffer().
    • Reads the request body for all methods except GET and HEAD (forwarding DELETE and OPTIONS bodies as well).
  2. Regression tests (tests/routes/proxy-binary-body.test.ts):
    • Added unit tests covering POST, PUT, PATCH, DELETE, and OPTIONS against a local upstream server using invalid UTF-8 byte sequences ([0x00, 0xff, 0xfe, 0x80, 0x41]).
    • Asserts exact binary equivalence on the proxied response.

Validation

  • bun test: 34 passed, 0 failed across 10 files (180 assertions).
  • bun x tsc --noEmit: 0 type errors.
  • bun x @biomejs/biome format: verified clean.

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)

1 participant