{
  "id": "nginx/upstream-sent-invalid-content-length-zero-body",
  "signature": "upstream sent invalid Content-Length: 0 with non-empty body while reading response header from upstream, client: 10.0.0.1, server: example.com",
  "signature_zh": "上游发送了无效的 Content-Length：0 但主体非空，从上游读取响应头时，客户端：10.0.0.1，服务器：example.com",
  "regex": "upstream sent invalid Content-Length: 0 with non-empty body while reading response header from upstream",
  "domain": "nginx",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "Upstream sends a Content-Length of 0 but then includes a non-empty response body, causing nginx to detect a mismatch and abort.",
  "root_cause_type": "generic",
  "root_cause_zh": "上游发送了 Content-Length 为 0 但随后包含了非空的响应主体，导致 nginx 检测到不匹配并终止。",
  "versions": [
    {
      "version": "nginx 1.18.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.20.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.22.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.24.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Set proxy_request_buffering off;",
      "why_fails": "Request buffering affects client request body, not response body handling from upstream.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase proxy_buffer_size",
      "why_fails": "Buffer size does not affect the Content-Length validation logic; the error is about header-body mismatch.",
      "fail_rate": 0.93,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disable chunked transfer encoding with proxy_set_header Transfer-Encoding '';",
      "why_fails": "This modifies request headers to upstream, not the response; the error is in the response.",
      "fail_rate": 0.88,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Fix the upstream application to correctly set Content-Length to the actual body size. For example, in a Go HTTP handler, ensure Content-Length matches the body:\nfunc handler(w http.ResponseWriter, r *http.Request) {\n    body := []byte(\"Hello\")\n    w.Header().Set(\"Content-Length\", strconv.Itoa(len(body)))\n    w.Write(body)\n}\nAvoid hardcoding Content-Length to 0 when writing a body.",
      "success_rate": 0.85,
      "how": "Fix the upstream application to correctly set Content-Length to the actual body size. For example, in a Go HTTP handler, ensure Content-Length matches the body:\nfunc handler(w http.ResponseWriter, r *http.Request) {\n    body := []byte(\"Hello\")\n    w.Header().Set(\"Content-Length\", strconv.Itoa(len(body)))\n    w.Write(body)\n}\nAvoid hardcoding Content-Length to 0 when writing a body.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use nginx's proxy_hide_header Content-Length; to remove the upstream's Content-Length header, forcing nginx to use chunked encoding or calculate length from the actual body. Example:\nlocation / {\n    proxy_pass http://upstream;\n    proxy_hide_header Content-Length;\n}",
      "success_rate": 0.72,
      "how": "Use nginx's proxy_hide_header Content-Length; to remove the upstream's Content-Length header, forcing nginx to use chunked encoding or calculate length from the actual body. Example:\nlocation / {\n    proxy_pass http://upstream;\n    proxy_hide_header Content-Length;\n}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Fix the upstream application to correctly set Content-Length to the actual body size. For example, in a Go HTTP handler, ensure Content-Length matches the body:\nfunc handler(w http.ResponseWriter, r *http.Request) {\n    body := []byte(\"Hello\")\n    w.Header().Set(\"Content-Length\", strconv.Itoa(len(body)))\n    w.Write(body)\n}\nAvoid hardcoding Content-Length to 0 when writing a body.",
    "Use nginx's proxy_hide_header Content-Length; to remove the upstream's Content-Length header, forcing nginx to use chunked encoding or calculate length from the actual body. Example:\nlocation / {\n    proxy_pass http://upstream;\n    proxy_hide_header Content-Length;\n}"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.74,
  "resolvable": "true",
  "first_seen": "2024-06-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}