Skip to content

Multipart form-data body builder#12

Merged
OmarAlJarrah merged 4 commits into
mainfrom
feat/formdata
Jun 16, 2026
Merged

Multipart form-data body builder#12
OmarAlJarrah merged 4 commits into
mainfrom
feat/formdata

Conversation

@OmarAlJarrah

Copy link
Copy Markdown
Member

Summary

Adds a formdata package — an ergonomic builder over mime/multipart for
multipart/form-data request bodies (file uploads), producing a replayable
body so retries can re-send it.

What's included

  • Form — chainable, deferred-error builder: Field(name, value),
    File(field, filename, r), FileBytes(field, filename, data). The first error
    is reported at Build; no panics.
  • ContentType() — the multipart/form-data; boundary=… content type.
  • Build() (*bytes.Reader, error) — finalizes the form into an in-memory,
    replayable body (so http.NewRequest populates GetBody).
  • NewRequest(ctx, method, url) — the ergonomic entry point: returns a ready
    *http.Request with the multipart Content-Type set and a replayable body.

Background

This was one of the items deferred from the HTTP-value-types roadmap subsystem.
It buffers the body in memory (the documented default) so it survives the retry
policy's body replay; streaming non-replayable uploads remain out of scope.

Behavior changes

None — new package only.

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l . (clean)
  • go test -race ./... (all packages pass)
  • Covered: build a field + file and parse it back with mime/multipart (field
    value and file name/content round-trip); NewRequest sets the boundary
    Content-Type and yields a replayable body (read via Body then GetBody); a
    failing file reader surfaces at Build; build-twice and field-after-build
    error; an empty form builds a valid body.

🤖 Generated with Claude Code

OmarAlJarrah and others added 4 commits June 16, 2026 21:11
Chainable Form builder over mime/multipart producing a replayable body and the
boundary Content-Type, with a NewRequest convenience.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@OmarAlJarrah OmarAlJarrah merged commit 8fa1765 into main Jun 16, 2026
1 of 2 checks passed
@OmarAlJarrah OmarAlJarrah deleted the feat/formdata branch June 16, 2026 18:17
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