{"record":{"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":614,"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":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/gofiber/fiber/blob/a105acad6c1e4576a77f01e02973f67e962bb58d/middleware/adaptor/adaptor.go#L596-L632","documentation":"The net/http -> fasthttp adaptor (HTTPHandlerFunc / adaptor's handlerFunc) enforces the Fiber app's BodyLimit on inbound request bodies before copying them into the fasthttp request. When the request's declared Content-Length exceeds app.Config().BodyLimit (default 4 * 1024 * 1024 = 4 MiB), the adaptor writes a 413 Request Entity Too Large response and stops processing — it does not panic, and the process keeps serving other requests. A LimitedReader also caps the actual streamed bytes at BodyLimit+1 so a client lying about Content-Length cannot exhaust memory.","triggerScenarios":"A client POST/PUT whose Content-Length header exceeds the configured BodyLimit reaches a route mounted via adaptor.HTTPHandlerFunc or adaptor.FiberApp wrapped in net/http. Default limit is 4 MiB; a file upload, large JSON payload, or webhook exceeding it triggers the 413.","commonSituations":"File uploads through an adaptor-mounted handler; a webhook receiver whose payloads grew past 4 MiB; a default-config app receiving legitimate large bodies; migrating a net/http handler to Fiber via the adaptor without raising BodyLimit to match the prior server's limit.","solutions":["Raise app.Config().BodyLimit (fiber.Config{BodyLimit: ...}) when large bodies are expected — set it on fiber.New(Config{BodyLimit: 32 << 20}).","Move large-body endpoints (uploads) to streaming or multipart handling rather than buffering the whole body.","Reject or chunk oversized payloads at the reverse proxy / load balancer upstream of the app."],"exampleFix":"// before\napp := fiber.New() // BodyLimit defaults to 4 MiB\nhttp.ListenAndServe(\":8080\", adaptor.HTTPHandler(app, bigUploadHandler))\n\n// after\napp := fiber.New(fiber.Config{\n    BodyLimit: 64 * 1024 * 1024, // 64 MiB for upload routes\n})\nhttp.ListenAndServe(\":8080\", adaptor.HTTPHandler(app, bigUploadHandler))","handlingStrategy":"validation","validationCode":"func bodyLimitFor(route string) int {\n    if strings.HasPrefix(route, \"/upload\") { return 64 * 1024 * 1024 }\n    return 4 * 1024 * 1024 // default\n}\n// app := fiber.New(fiber.Config{BodyLimit: bodyLimitFor(\"/upload\")})\n//\n// client-side guard before sending:\n// if fileSize > int64(app.Config().BodyLimit) { return fmt.Errorf(\"file too large\") }","typeGuard":"func requestWithinLimit(contentLength int64, bodyLimit int) bool {\n    return contentLength <= int64(bodyLimit)\n}","tryCatchPattern":null,"preventionTips":["Set BodyLimit explicitly on fiber.New to match the largest legitimate payload, rather than relying on the 4 MiB default.","Handle large uploads via streaming/multipart instead of buffering the whole body.","Reject oversized payloads at the upstream reverse proxy so they never reach the app.","Remember the adaptor applies Fiber's BodyLimit even though the request arrives through net/http."],"tags":["adaptor","body-limit","http","config","middleware"],"backgroundTag":null,"analyzedSha":"a105acad6c1e4576a77f01e02973f67e962bb58d","analyzedAt":"2026-08-11T17:33:26.942Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}