{
  "id": "nginx/upstream-sent-invalid-content-length-negative",
  "signature": "upstream sent invalid Content-Length: -1 while reading response header from upstream",
  "signature_zh": "上游发送了无效的Content-Length：-1，同时从上游读取响应头",
  "regex": "upstream sent invalid Content-Length: -\\d+ while reading response header from upstream",
  "domain": "nginx",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "Upstream server returns a negative Content-Length value in the HTTP response, which violates HTTP specification.",
  "root_cause_type": "generic",
  "root_cause_zh": "",
  "versions": [
    {
      "version": "nginx 1.24.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.25.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "nginx 1.26.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Add proxy_buffering off;",
      "why_fails": "Buffering does not fix an invalid header value from upstream.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Increase proxy_buffer_size",
      "why_fails": "This addresses header size, not header validity.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    },
    {
      "action": "Restart nginx",
      "why_fails": "Restarting does not change the upstream behavior.",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use proxy_ignore_headers to ignore the Content-Length header from upstream:\n  location / {\n      proxy_pass http://upstream;\n      proxy_ignore_headers Content-Length;\n  }",
      "success_rate": 0.85,
      "how": "Use proxy_ignore_headers to ignore the Content-Length header from upstream:\n  location / {\n      proxy_pass http://upstream;\n      proxy_ignore_headers Content-Length;\n  }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Fix the upstream application to emit a valid Content-Length (non-negative integer). For example, in a Python Flask app:\n  from flask import Response\n  @app.route('/data')\n  def data():\n      body = 'hello'\n      return Response(body, headers={'Content-Length': str(len(body))})",
      "success_rate": 0.95,
      "how": "Fix the upstream application to emit a valid Content-Length (non-negative integer). For example, in a Python Flask app:\n  from flask import Response\n  @app.route('/data')\n  def data():\n      body = 'hello'\n      return Response(body, headers={'Content-Length': str(len(body))})",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use proxy_ignore_headers to ignore the Content-Length header from upstream:\n  location / {\n      proxy_pass http://upstream;\n      proxy_ignore_headers Content-Length;\n  }",
    "Fix the upstream application to emit a valid Content-Length (non-negative integer). For example, in a Python Flask app:\n  from flask import Response\n  @app.route('/data')\n  def data():\n      body = 'hello'\n      return Response(body, headers={'Content-Length': str(len(body))})"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2025-02-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}