go
network_error
ai_generated
true
http: invalid Content-Length
ID: go/http-multiple-content-length
80%Fix Rate
85%Confidence
0Evidence
2024-05-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.22 | active | — | — | — |
Root Cause
The HTTP request or response contains multiple Content-Length headers with different values, causing Go's net/http to reject it as invalid.
generic中文
HTTP请求或响应包含多个值不同的Content-Length头,导致Go的net/http拒绝该请求。
Workarounds
-
75% success
if req.Header.Get("Content-Length") != "" { // Validate and use a single value } else { // Handle missing Content-Length } -
80% success
Use a custom RoundTripper to sanitize headers before sending.
Dead Ends
Common approaches that don't work:
-
80% fail
The body may be corrupted or incomplete, leading to data integrity issues.
-
60% fail
Does not resolve the underlying inconsistency and may cause parsing errors.