go config_error ai_generated true

error: http: request body too large

ID: go/net-http-request-body-too-large

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2026-05-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.20 active — — —
1.21 active — — —

Root Cause

The HTTP request body exceeds the server's maximum body size limit, controlled by http.MaxBytesReader.

generic

中文

HTTP请求体超过服务器的最大体大小限制,由http.MaxBytesReader控制。

Workarounds

  1. 95% success Use http.MaxBytesReader to limit request body size
    r.Body = http.MaxBytesReader(w, r.Body, 10<<20) // 10 MB
    if err := json.NewDecoder(r.Body).Decode(&data); err != nil { /* handle */ }

Dead Ends

Common approaches that don't work:

  1. Setting MaxBytesReader to unlimited 30% fail

    Security risk; always set a limit.