{"id":"31e85aa3344ac330","repo":"gofiber/fiber","slug":"request-entity-too-large","errorCode":null,"errorMessage":"Request Entity Too Large","messagePattern":"Request Entity Too Large","errorType":"http","errorClass":null,"httpStatus":413,"severity":"warning","filePath":"middleware/adaptor/adaptor.go","lineNumber":499,"sourceCode":"\t\t\tremoteAddr = nil // Fallback to nil\n\t\t}\n\t\tpctx.conn.remoteAddr = remoteAddr\n\n\t\t// Init2 mirrors fasthttp's RequestCtx.Init, but with a no-op\n\t\t// connection instead of fasthttp's fakeAddrer, whose Write panics.\n\t\t// Interim responses (e.g. SendEarlyHints' 103) are then silently\n\t\t// discarded instead of panicking; the final response still reaches\n\t\t// the client through the ResponseWriter copy-back below. Init2 only\n\t\t// touches connection metadata and buffer-retention flags, so the\n\t\t// request is built directly into fctx.Request afterwards — the same\n\t\t// order fasthttp's Init uses, minus its full request copy.\n\t\tfctx.Init2(&pctx.conn, disabledLogger, true)\n\t\treq := &fctx.Request\n\n\t\t// Convert net/http -> fasthttp request with size limit\n\t\tif r.Body != nil {\n\t\t\tif r.ContentLength > maxBodySize {\n\t\t\t\thttp.Error(w, utils.StatusMessage(fiber.StatusRequestEntityTooLarge), fiber.StatusRequestEntityTooLarge)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tvar n int64\n\t\t\t// http.NoBody never yields any bytes, so skip the copy machinery\n\t\t\t// entirely for the (very common) bodyless request.\n\t\t\tif r.Body != http.NoBody {\n\t\t\t\tlimit := maxBodySize\n\t\t\t\tif limit < math.MaxInt64 {\n\t\t\t\t\tlimit++\n\t\t\t\t}\n\t\t\t\t// The LimitedReader lives in the pooled ctx and the copy\n\t\t\t\t// buffer comes from the shared pool: io.Copy would otherwise\n\t\t\t\t// allocate a fresh 32 KiB buffer on every single request.\n\t\t\t\tpctx.lr.R = r.Body\n\t\t\t\tpctx.lr.N = limit\n\n\t\t\t\tvar err error","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/gofiber/fiber/blob/9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c/middleware/adaptor/adaptor.go#L481-L517","documentation":"Returns HTTP 413 'Request Entity Too Large' from middleware/adaptor/adaptor.go:499 inside the net/http -> fasthttp adaptor when the incoming request's declared Content-Length exceeds maxBodySize. maxBodySize is derived from the Fiber app's BodyLimit (default DefaultBodyLimit = 4 MiB, app.go:613). The same 413 is re-sent at line 526 if the streamed bytes exceed the limit despite a missing/lying Content-Length.","triggerScenarios":"Serving a Fiber app behind net/http via the adaptor and POSTing/PUTting a body larger than BodyLimit with a Content-Length header that exceeds it; chunked uploads that cross the limit mid-stream. This is a normal HTTP response, not a Go panic/error to the caller.","commonSituations":"File/image uploads exceeding the 4 MiB default; JSON batches; clients that did not pre-flight the size; default BodyLimit left in place for an upload endpoint.","solutions":["Raise BodyLimit for upload routes: fiber.New(fiber.Config{BodyLimit: 50 * 1024 * 1024}).","Have the client chunk large uploads or stream to a dedicated upload endpoint with a higher limit.","Reject oversized requests at the reverse proxy (nginx client_max_body_size) before they reach the app."],"exampleFix":"// before\napp := fiber.New() // BodyLimit defaults to 4 MiB\n// client POSTs a 10 MiB file -> 413\n\n// after\napp := fiber.New(fiber.Config{\n    BodyLimit: 64 * 1024 * 1024, // 64 MiB for upload routes\n})","handlingStrategy":"validation","validationCode":"// Validate client-side before sending.\nconst limit = 4 * 1024 * 1024 // match BodyLimit\nif r.ContentLength > limit {\n    return fmt.Errorf(\"body too large: %d bytes\", r.ContentLength)\n}\n// or raise the server limit:\napp := fiber.New(fiber.Config{BodyLimit: 64 * 1024 * 1024})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set BodyLimit high enough for the largest legitimate upload on that route.","Enforce a size cap at the reverse proxy (e.g. nginx client_max_body_size).","Have clients pre-flight sizes and chunk large uploads."],"tags":["adaptor","net-http","body-limit","http-413","middleware"],"analyzedSha":"9a4c7e57fe0b080a04235d28a4b0d2b4b353d58c","analyzedAt":"2026-08-04T21:44:03.395Z","schemaVersion":2}