valyala/fasthttp · error
fasthttp: request content-type has bad boundary or is not mu
Error message
fasthttp: request content-type has bad boundary or is not multipart/form-data
What it means
Request.MultipartForm() parses the body as multipart/form-data, which requires a Content-Type of multipart/form-data with a valid boundary parameter. If the Content-Type is missing, is another type, or the boundary is bad, fasthttp returns ErrNoMultipartForm.
Source
Thrown at http.go:1120
req.parsePostArgs()
return &req.postArgs
}
func (req *Request) parsePostArgs() {
if req.parsedPostArgs {
return
}
req.parsedPostArgs = true
if !bytes.HasPrefix(req.Header.ContentType(), strPostArgsContentType) {
return
}
req.postArgs.ParseBytes(req.bodyBytes())
}
// ErrNoMultipartForm means that the request's Content-Type
// isn't 'multipart/form-data'.
var ErrNoMultipartForm = errors.New("fasthttp: request content-type has bad boundary or is not multipart/form-data")
// MultipartForm returns request's multipart form.
//
// Returns ErrNoMultipartForm if request's Content-Type
// isn't 'multipart/form-data'.
//
// This method is equivalent to MultipartFormWithLimit(0), i.e. no body size
// limit is applied during multipart parsing.
//
// RemoveMultipartFormFiles must be called after returned multipart form
// is processed.
func (req *Request) MultipartForm() (*multipart.Form, error) {
return req.MultipartFormWithLimit(0)
}
// MultipartFormWithLimit returns request's multipart form and limits the
// read multipart body size to maxBodySize bytes.
//View on GitHub (pinned to c96f600972)
Solutions
- Check req.Header.ContentType() (or strings.HasPrefix) for multipart/form-data before calling MultipartForm, and handle urlencoded via req.PostArgs otherwise.
- Fix the client/form to send enctype="multipart/form-data" with a proper boundary.
- For non-multipart uploads, read the body directly (req.Body()) instead of forcing multipart parsing.
- Reject unsupported content types with 415 Unsupported Media Type in your handler.
Example fix
// before
form, err := req.MultipartForm()
// after
if !strings.HasPrefix(string(req.Header.ContentType()), "multipart/form-data") {
// handle urlencoded/plain body instead
req.PostArgs()
return
}
form, err := req.MultipartForm() Defensive patterns
Strategy: validation
Validate before calling
mediaType, params, _ := mime.ParseMediaType(string(req.Header.ContentType())) isMultipart := mediaType == "multipart/form-data" && params["boundary"] != ""
Try / catch
form, err := req.MultipartForm()
if errors.Is(err, fasthttp.ErrNoMultipartForm) {
// respond 415 or parse urlencoded body instead
} Prevention
- Set enctype="multipart/form-data" on upload forms
- Verify Content-Type before calling MultipartForm
- Handle urlencoded bodies via req.PostArgs
- Return 415 for unsupported content types
When it happens
Trigger: Calling req.MultipartForm() when the request Content-Type isn't 'multipart/form-data; boundary=...' — e.g. a JSON POST, application/x-www-form-urlencoded POST, or a multipart body with a malformed/missing boundary.
Common situations: Endpoint assumed multipart but clients send JSON; file-upload forms missing the enctype='multipart/form-data' attribute; hand-rolled multipart bodies with wrong boundary; callers not checking IsPost/Content-Type first.
Related errors
- form boundary cannot be empty
- fasthttp: contain forbidden trailer
- fasthttp: error when reading response headers
- fasthttp: error when reading response trailer
- fasthttp: cannot find whitespace in the first line of respon
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/c49784b61aa7db2f.
Report an issue: GitHub.