{"record":{"id":"c49784b61aa7db2f","repo":"valyala/fasthttp","slug":"fasthttp-request-content-type-has-bad-boundary-or","errorCode":null,"errorMessage":"fasthttp: request content-type has bad boundary or is not multipart/form-data","messagePattern":"fasthttp: request content-type has bad boundary or is not multipart/form-data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"http.go","lineNumber":1120,"sourceCode":"\treq.parsePostArgs()\n\treturn &req.postArgs\n}\n\nfunc (req *Request) parsePostArgs() {\n\tif req.parsedPostArgs {\n\t\treturn\n\t}\n\treq.parsedPostArgs = true\n\n\tif !bytes.HasPrefix(req.Header.ContentType(), strPostArgsContentType) {\n\t\treturn\n\t}\n\treq.postArgs.ParseBytes(req.bodyBytes())\n}\n\n// ErrNoMultipartForm means that the request's Content-Type\n// isn't 'multipart/form-data'.\nvar ErrNoMultipartForm = errors.New(\"fasthttp: request content-type has bad boundary or is not multipart/form-data\")\n\n// MultipartForm returns request's multipart form.\n//\n// Returns ErrNoMultipartForm if request's Content-Type\n// isn't 'multipart/form-data'.\n//\n// This method is equivalent to MultipartFormWithLimit(0), i.e. no body size\n// limit is applied during multipart parsing.\n//\n// RemoveMultipartFormFiles must be called after returned multipart form\n// is processed.\nfunc (req *Request) MultipartForm() (*multipart.Form, error) {\n\treturn req.MultipartFormWithLimit(0)\n}\n\n// MultipartFormWithLimit returns request's multipart form and limits the\n// read multipart body size to maxBodySize bytes.\n//","sourceCodeStart":1102,"sourceCodeEnd":1138,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/http.go#L1102-L1138","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nform, err := req.MultipartForm()\n// after\nif !strings.HasPrefix(string(req.Header.ContentType()), \"multipart/form-data\") {\n    // handle urlencoded/plain body instead\n    req.PostArgs()\n    return\n}\nform, err := req.MultipartForm()","handlingStrategy":"validation","validationCode":"mediaType, params, _ := mime.ParseMediaType(string(req.Header.ContentType()))\nisMultipart := mediaType == \"multipart/form-data\" && params[\"boundary\"] != \"\"","typeGuard":null,"tryCatchPattern":"form, err := req.MultipartForm()\nif errors.Is(err, fasthttp.ErrNoMultipartForm) {\n    // respond 415 or parse urlencoded body instead\n}","preventionTips":["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"],"tags":["http","multipart","content-type","fasthttp"],"backgroundTag":"not-multipart-form-data","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}