go network_error ai_generated true

http:无效的Content-Length

http: invalid Content-Length

ID: go/http-multiple-content-length

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
0证据数
2024-05-20首次发现

版本兼容性

版本状态引入弃用备注
1.22 active

根因分析

HTTP请求或响应包含多个值不同的Content-Length头,导致Go的net/http拒绝该请求。

English

The HTTP request or response contains multiple Content-Length headers with different values, causing Go's net/http to reject it as invalid.

generic

解决方案

  1. 75% 成功率
    if req.Header.Get("Content-Length") != "" {
        // Validate and use a single value
    } else {
        // Handle missing Content-Length
    }
  2. 80% 成功率
    Use a custom RoundTripper to sanitize headers before sending.

无效尝试

常见但无效的做法:

  1. 80% 失败

    The body may be corrupted or incomplete, leading to data integrity issues.

  2. 60% 失败

    Does not resolve the underlying inconsistency and may cause parsing errors.