Multipart form-data body builder#12
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
formdatapackage — an ergonomic builder overmime/multipartformultipart/form-datarequest bodies (file uploads), producing a replayablebody 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 erroris reported at
Build; no panics.ContentType()— themultipart/form-data; boundary=…content type.Build() (*bytes.Reader, error)— finalizes the form into an in-memory,replayable body (so
http.NewRequestpopulatesGetBody).NewRequest(ctx, method, url)— the ergonomic entry point: returns a ready*http.Requestwith the multipartContent-Typeset 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)mime/multipart(fieldvalue and file name/content round-trip);
NewRequestsets the boundaryContent-Type and yields a replayable body (read via
BodythenGetBody); afailing file reader surfaces at
Build; build-twice and field-after-builderror; an empty form builds a valid body.
🤖 Generated with Claude Code