{"record":{"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/d1cbca76970939a9c2ced55b1e25ea26f34fc773/src/Handler/HeaderProcessor.php#L96-L132","documentation":"Thrown by HeaderProcessor::parseContentLength() when a Content-Length value, after trimming spaces/tabs and splitting on commas, does not match ^[0-9]+$. Content-Length must be a single non-negative decimal integer; signed, decimal, hex, or empty values are rejected per RFC 7230. The same validator runs for both request and response Content-Length.","triggerScenarios":"A server sends 'Content-Length: 1.5', 'Content-Length: -5', 'Content-Length: 0x10', 'Content-Length:' (empty), or 'Content-Length: 1024;' (trailing semicolon). Also triggered on the request side when a caller sets Content-Length to a non-integer string.","commonSituations":"Origin server bug, a CDN rewriting bodies but leaving a stale/decimal length, custom middleware setting Content-Length to a computed float, or proxy concatenation producing malformed values.","solutions":["Inspect the actual Content-Length header on the wire (curl -v, on_headers) to see the malformed value.","Remove any manually set Content-Length on the request and let Guzzle compute it from the body size.","Report the malformed header to the server/CDN operator.","Catch RuntimeException when you must interoperate with the broken endpoint."],"exampleFix":"// before - manually forcing a bad length\n$request = new \\GuzzleHttp\\Psr7\\Request('POST', $url, ['Content-Length' => '1.5'], $body);\n\n// after - let Guzzle derive the length\n$request = new \\GuzzleHttp\\Psr7\\Request('POST', $url, [], $body);","handlingStrategy":"try-catch","validationCode":"// For request-side Content-Length, never set it manually; let Guzzle compute it.\n// If you must set it, validate first:\nif ($cl !== null && preg_match('/^[0-9]+$/D', (string) $cl) !== 1) {\n    throw new \\InvalidArgumentException('Bad Content-Length');\n}","typeGuard":"function isValidContentLength(?string $value): bool {\n    return $value === null || preg_match('/^[0-9]+$/D', $value) === 1;\n}","tryCatchPattern":"try {\n    $response = $client->get($url);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'not a non-negative decimal integer')) {\n        // surface the bad header value to logs\n    }\n    throw $e;\n}","preventionTips":["Never set Content-Length manually on requests; let Guzzle derive it from the body.","Use on_headers to inspect server-sent Content-Length during debugging.","Report malformed server headers to the endpoint owner."],"tags":["http","content-length","headers","php","guzzle"],"backgroundTag":null,"analyzedSha":"d1cbca76970939a9c2ced55b1e25ea26f34fc773","analyzedAt":"2026-08-06T00:37:27.795Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}