{"id":"7be6800f840fd28c","repo":"guzzle/guzzle","slug":"value-is-not-a-non-negative-decimal-integer","errorCode":null,"errorMessage":"value is not a non-negative decimal integer","messagePattern":"value is not a non-negative decimal integer","errorType":"exception","errorClass":"\\RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Handler/HeaderProcessor.php","lineNumber":114,"sourceCode":"        return \\preg_match('/^[\\x20\\x09\\x21-\\x7E\\x80-\\xFF]*(?:\\r\\n|\\r|\\n)?$/D', \\trim($parts[1], \" \\t\")) === 1;\n    }\n\n    /**\n     * Returns a normalized decimal Content-Length, or null when absent.\n     *\n     * @param string[] $values\n     *\n     * @throws \\RuntimeException when Content-Length is malformed or conflicting.\n     */\n    public static function parseContentLength(array $values): ?string\n    {\n        $length = null;\n\n        foreach ($values as $value) {\n            foreach (\\explode(',', $value) as $part) {\n                $part = \\trim($part, \" \\t\");\n                if (\\preg_match('/^[0-9]+$/D', $part) !== 1) {\n                    throw new \\RuntimeException('value is not a non-negative decimal integer');\n                }\n\n                $part = \\ltrim($part, '0');\n                $part = $part === '' ? '0' : $part;\n                if ($length !== null && $part !== $length) {\n                    throw new \\RuntimeException('values conflict');\n                }\n\n                $length = $part;\n            }\n        }\n\n        if ($length === null) {\n            return null;\n        }\n\n        return $length;\n    }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/guzzle/guzzle/blob/9b200fc5805036b331d6031199880dadecae0275/src/Handler/HeaderProcessor.php#L96-L132","documentation":"Thrown by HeaderProcessor::parseContentLength() when any comma-separated part of a Content-Length value fails the ^[0-9]+$ check. Content-Length must be a single non-negative decimal integer per RFC 7230; anything else (a float, a sign, text) is rejected as an anti-smuggling measure. Raised as \\RuntimeException.","triggerScenarios":"The server (or an intermediary) returns 'Content-Length: 1.0', 'Content-Length: -5', 'Content-Length: abc', or a quoted value. Any handler path that parses response Content-Length hits it.","commonSituations":"A buggy origin that sends a float Content-Length, a proxy that rewrites headers incorrectly, or a chunked response where a middlebox injected a bad Content-Length.","solutions":["Capture the response headers to confirm the malformed Content-Length value","Fix the origin server or the intermediary that produced it","try/catch the request to handle the malformed response defensively"],"exampleFix":"try {\n    $resp = $client->get($url);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'non-negative decimal integer')) {\n        // server sent an invalid Content-Length\n    }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $response = $client->request('GET', $url);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'non-negative decimal integer')) {\n        // server returned an invalid Content-Length\n    }\n}","preventionTips":["When you control the server, always emit a single integer Content-Length","Inspect response headers in debug mode when integrating a new upstream","Wrap third-party upstream calls so a bad header cannot crash your process"],"tags":["content-length","headers","validation","response-framing"],"analyzedSha":"9b200fc5805036b331d6031199880dadecae0275","analyzedAt":"2026-08-04T21:24:26.648Z","schemaVersion":2}