go
runtime_error
ai_generated
true
http: wrote more than the declared Content-Length
ID: go/http-header-write-after-write
80%Fix Rate
85%Confidence
0Evidence
2024-07-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Handler set Content-Length header explicitly but wrote more bytes than declared, or middleware re-wrote the body.
generic中文
处理程序显式设置了 Content-Length 但写入的字节数超出声明,或中间件重写了 body。
Workarounds
-
90% success
Buffer the response with bytes.Buffer, then set Content-Length to buf.Len() before w.Write.
-
92% success
Do not set Content-Length manually; let net/http chunk or compute it.
Dead Ends
Common approaches that don't work:
-
85% fail
Clients hang waiting for the remaining bytes.
-
90% fail
Headers already sent; no effect.