{"record":{"id":"50bbf90841ff1830","repo":"rohitg00/ai-engineering-from-scratch","slug":"duplicate-content-length-headers-are-not-allowed","errorCode":null,"errorMessage":"duplicate Content-Length headers are not allowed","messagePattern":"duplicate Content-Length headers are not allowed","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"phases/13-tools-and-protocols/09-mcp-transports/code/main.py","lineNumber":242,"sourceCode":"    if not callable(get_all):\n        return\n    for name in ROUTING_HEADERS:\n        if len(get_all(name, [])) > 1:\n            raise RpcFault(-32020, f\"Duplicate routing header: {name}\")\n\n\ndef reject_duplicate_origin(headers: Any) -> None:\n    get_all = getattr(headers, \"get_all\", None)\n    if callable(get_all) and len(get_all(\"Origin\", [])) > 1:\n        raise RpcFault(-32020, \"Duplicate Origin header\")\n\n\ndef reject_ambiguous_body_framing(headers: Any) -> None:\n    get_all = getattr(headers, \"get_all\", None)\n    if not callable(get_all):\n        return\n    if len(get_all(\"Content-Length\", [])) > 1:\n        raise ValueError(\"duplicate Content-Length headers are not allowed\")\n    if get_all(\"Transfer-Encoding\", []):\n        raise ValueError(\"Transfer-Encoding is not supported\")\n\n\ndef dispatch(message: dict[str, Any]) -> dict[str, Any] | None:\n    if \"id\" not in message:\n        return None\n    request_id = message[\"id\"]\n    try:\n        version = validate_request_structure(message)\n        validate_supported_version(version)\n        method = message[\"method\"]\n        params = message[\"params\"]\n        if method == \"server/discover\":\n            result = complete(\n                {\n                    \"supportedVersions\": SUPPORTED_VERSIONS.copy(),\n                    \"capabilities\": SERVER_CAPABILITIES.copy(),","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/13-tools-and-protocols/09-mcp-transports/code/main.py#L224-L260","documentation":"HTTP request-smuggling defense in reject_ambiguous_body_framing: more than one Content-Length header was received; conflicting lengths make body framing ambiguous, so the request is rejected outright instead of picking one value.","triggerScenarios":"Thrown at phases/13-tools-and-protocols/09-mcp-transports/code/main.py:242 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send exactly one Content-Length header","Fix proxy or client code that appends rather than sets headers","Reject duplicates at the load balancer so ambiguity never reaches the app"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}