{"record":{"id":"8ae48d6f1b92eb14","repo":"guzzle/guzzle","slug":"invalid-content-length-response-header-s","errorCode":null,"errorMessage":"Invalid Content-Length response header: %s","messagePattern":"Invalid Content-Length response header: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Handler/HeaderProcessor.php","lineNumber":184,"sourceCode":"     * @throws \\RuntimeException when Content-Length is malformed, conflicting,\n     *                           or combined with Transfer-Encoding\n     */\n    public static function validateResponseFraming(\n        string $method,\n        int $status,\n        array $headers\n    ): ?string {\n        if (!self::responseCanHaveBody($method, $status)) {\n            return null;\n        }\n\n        $normalizedKeys = Utils::normalizeHeaderKeys($headers);\n        $contentLength = self::removeHeader('Content-Length', $headers);\n\n        try {\n            $length = self::parseContentLength($contentLength);\n        } catch (\\RuntimeException $e) {\n            throw new \\RuntimeException('Invalid Content-Length response header: '.$e->getMessage(), 0, $e);\n        }\n\n        if ($length !== null && isset($normalizedKeys['transfer-encoding'])) {\n            throw new \\RuntimeException('A response must not contain both Content-Length and Transfer-Encoding');\n        }\n\n        return $length;\n    }\n\n    /**\n     * Removes every case-insensitive occurrence of a header and returns all\n     * removed values in their original field order.\n     *\n     * @param array<string, string[]> $headers\n     *\n     * @return string[] Removed values across all header-name casings\n     */\n    public static function removeHeader(string $name, array &$headers): array","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/guzzle/guzzle/blob/d1cbca76970939a9c2ced55b1e25ea26f34fc773/src/Handler/HeaderProcessor.php#L166-L202","documentation":"Thrown by HeaderProcessor::validateResponseFraming() as a wrapper RuntimeException that re-throws any Content-Length parse failure (error 281 or 282) with a response-specific prefix. It preserves the original cause via the $previous argument. It fires only for responses that are allowed to have a body (excludes HEAD, 1xx, 204, 304, 2xx CONNECT).","triggerScenarios":"A response to a body-bearing request carries a malformed or conflicting Content-Length header; validateResponseFraming() catches the underlying RuntimeException from parseContentLength() and rethrows with the 'Invalid Content-Length response header: ' prefix.","commonSituations":"Same root causes as errors 281/282 but surfaced during response framing validation, typically against a buggy server, gateway, or CDN emitting bad Content-Length.","solutions":["Read the suffixed detail (the original message) to know whether it was non-integer (281) or conflicting (282).","Capture raw response headers to confirm what the server sent.","Report/fix the origin or intermediary producing the bad header.","Catch RuntimeException around the request when interoperating with the broken endpoint."],"exampleFix":"// before\ntry {\n    $resp = $client->get($url);\n} catch (\\GuzzleHttp\\Exception\\RequestException $e) {\n    // message is opaque\n}\n\n// after - surface the underlying cause\ntry {\n    $resp = $client->get($url);\n} catch (\\RuntimeException $e) {\n    \\error_log($e->getMessage().' :: '.($e->getPrevious() ? $e->getPrevious()->getMessage() : ''));\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $response = $client->get($url);\n} catch (\\RuntimeException $e) {\n    if (str_starts_with($e->getMessage(), 'Invalid Content-Length response header')) {\n        $cause = $e->getPrevious() ? $e->getPrevious()->getMessage() : '';\n        // log $cause (e.g. 'values conflict' or 'not a non-negative decimal integer')\n    }\n    throw $e;\n}","preventionTips":["Inspect the previous exception for the precise sub-cause.","Capture raw response headers to identify server-side bad Content-Length.","Report framing bugs to the origin server or intermediary."],"tags":["http","content-length","response-framing","headers","php","guzzle"],"backgroundTag":null,"analyzedSha":"d1cbca76970939a9c2ced55b1e25ea26f34fc773","analyzedAt":"2026-08-06T00:37:27.795Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}