Skip to content

feat: add opt-in multipart form uploads - #81

Merged
fannnzhang merged 1 commit into
mainfrom
feature/multipart-form-uploads
Nov 13, 2026
Merged

fannnzhang merged 1 commit into
mainfrom
feature/multipart-form-uploads

Conversation

@fannnzhang

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in multipart feature that encodes multipart/form-data above Client::execute. Form / Part produce an ordinary RequestBody and own Content-Type; the connector and execution chain stay unchanged.

Request-body length is now independent of replayability:

  • RequestBody::content_length() is the construction-time DATA length. Bridge framing reads it, so a known-length one-shot stream uses Content-Length and still cannot be cloned.
  • RequestBody::concat composes DATA-only children without buffering payloads. from_stream_with_length counts bytes and rejects length mismatches while the source is polled.
  • from_body keeps an unknown framing length even when size_hint() is exact, so trailers are not suppressed.
  • HTTP/1.0 requests with a present body of unknown length fail as InvalidRequest before I/O. HTTP/2 uploads omit Transfer-Encoding.

Redirect follow-ups on the touched coordinator path now match the selected RFC 9110 behavior:

  • 301 / 302 rewrite POST to GET and drop the body. Other methods keep the method and body when the body is replayable.
  • 303 becomes GET, except HEAD, which stays HEAD.
  • 307 / 308 preserve the method. A one-shot body is returned to the caller instead of being replayed.
  • Retrieval rewrites also strip Content-Language, Content-Location, Digest, Last-Modified, Content-Digest, and Repr-Digest.

Replayable text/bytes forms can still be retried, redirected, and authenticated. A stream part, including one with a declared length, cannot.

Design notes and the requirement-to-test map are in docs/multipart-design.md.

Verification

  • cargo fmt --all --check
  • cargo test -p openwire-core --all-features --lib (56 passed)
  • cargo test -p openwire --all-features --lib --tests (lib 291 passed; integration suites including multipart, redirect, auth, pool_http2, events, and compression_bridge passed)
  • cargo build -p openwire --all-features --example post_multipart

Live-network tests stayed ignored.

Separate request-body length from replayability so a known-length
one-shot stream can use Content-Length without becoming replayable.
Encode multipart/form-data above Client::execute behind the multipart
feature, and align redirect follow-ups with the selected RFC 9110
method rules.
@fannnzhang
fannnzhang merged commit e74fa27 into main Nov 13, 2026
10 checks passed
@fannnzhang
fannnzhang deleted the feature/multipart-form-uploads branch November 13, 2026 07:02
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.

1 participant