Skip to content

fix(peer): keep FormData boundary case in encoded content-type - #186

Merged
dinwwwh merged 1 commit into
mainfrom
claude/stoic-faraday-6mota4
Nov 6, 2026
Merged

dinwwwh merged 1 commit into
mainfrom
claude/stoic-faraday-6mota4

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Nov 6, 2026

Copy link
Copy Markdown
Member

Fixes #182

Problem

encodeAtomicStandardBody set the content-type of a FormData body from blob.type. Blob.type is ASCII-lowercased, boundary included, while the serialized body keeps the original boundary. Chrome generates mixed-case boundaries (----WebKitFormBoundary…), so the receiving peer could not find the delimiter and formData() failed (TypeError: Failed to fetch). Firefox and Node use lowercase boundaries, which hid the bug.

Fix

  • peer: take the content-type from the Response headers, which keep the original case, and read it before blob(): Bun drops the header once a body containing a File has been consumed. This matches the node adapter.
  • node: comment only, noting the same read-before-body requirement on its existing response.headers.get('content-type')!.

Tests

  • New unit test in packages/peer/src/body.test.ts stubs Response to emit a Chrome-style mixed-case boundary, then checks the encoded header and a full encode → decode round trip. It fails without the fix.
  • The Bun ordering is covered by the existing bun-ws buffered body formdata e2e test, which fails when the header is read after blob().
  • pnpm check and pnpm test pass.

Generated by Claude Code

Blob.type is ASCII-lowercased, so using it as the content-type broke
mixed-case multipart boundaries (e.g. Chrome's ----WebKitFormBoundary...)
and the receiving side failed to parse the form data. Use the Response
content-type header instead, read before consuming the body since Bun
drops it afterwards when the FormData contains a File (same as the node
adapter).

Fixes #182

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VVaw7Qw8xM3RXrXjKh1gBc
@pullfrog

pullfrog Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

This run was cancelled before it finished.

Pullfrog  | View workflow run | via Pullfrog

@pkg-pr-new

pkg-pr-new Bot commented Nov 6, 2026

Copy link
Copy Markdown
@standard-server/aws-lambda

npm i https://pkg.pr.new/@standard-server/aws-lambda@186

@standard-server/core

npm i https://pkg.pr.new/@standard-server/core@186

@standard-server/fastify

npm i https://pkg.pr.new/@standard-server/fastify@186

@standard-server/fetch

npm i https://pkg.pr.new/@standard-server/fetch@186

@standard-server/node

npm i https://pkg.pr.new/@standard-server/node@186

@standard-server/peer

npm i https://pkg.pr.new/@standard-server/peer@186

@standard-server/shared

npm i https://pkg.pr.new/@standard-server/shared@186

commit: 1b72c33

@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dinwwwh
dinwwwh merged commit cfbacfc into main Nov 6, 2026
9 of 10 checks passed
@codspeed

codspeed Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 26 untouched benchmarks
⏩ 108 skipped benchmarks1


Comparing claude/stoic-faraday-6mota4 (1b72c33) with main (ca10b64)

Open in CodSpeed

Footnotes

  1. 108 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

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.

peer: form-data body fails to decode in Chrome (boundary gets lowercased)

2 participants