{"record":{"id":"12f90f23349ff5b2","repo":"moodle/moodle","slug":"dechunk-fail","errorCode":"dechunk_fail","errorMessage":"dechunk_fail","messagePattern":"dechunk_fail","errorType":"http","errorClass":"HttpException","httpStatus":null,"severity":"error","filePath":"public/lib/phpxmlrpc/src/Helper/Http.php","lineNumber":224,"sourceCode":"        if ($debug && count($httpResponse['headers'])) {\n            $msg = '';\n            foreach ($httpResponse['headers'] as $header => $value) {\n                $msg .= \"HEADER: $header: $value\\n\";\n            }\n            foreach ($httpResponse['cookies'] as $header => $value) {\n                $msg .= \"COOKIE: $header={$value['value']}\\n\";\n            }\n            $this->getLogger()->debug($msg);\n        }\n\n        // if CURL was used for the call, http headers have been processed, and dechunking + reinflating have been carried out\n        if (!$headersProcessed) {\n\n            // Decode chunked encoding sent by http 1.1 servers\n            if (isset($httpResponse['headers']['transfer-encoding']) && $httpResponse['headers']['transfer-encoding'] == 'chunked') {\n                if (!$data = static::decodeChunked($data)) {\n                    $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': errors occurred when trying to rebuild the chunked data received from server');\n                    throw new HttpException(PhpXmlRpc::$xmlrpcstr['dechunk_fail'], PhpXmlRpc::$xmlrpcerr['dechunk_fail'], null, $httpResponse['status_code']);\n                }\n            }\n\n            // Decode gzip-compressed stuff\n            // code shamelessly inspired from nusoap library by Dietrich Ayala\n            if (isset($httpResponse['headers']['content-encoding'])) {\n                $httpResponse['headers']['content-encoding'] = str_replace('x-', '', $httpResponse['headers']['content-encoding']);\n                if ($httpResponse['headers']['content-encoding'] == 'deflate' || $httpResponse['headers']['content-encoding'] == 'gzip') {\n                    // if decoding works, use it. else assume data wasn't gzencoded\n                    if (function_exists('gzinflate')) {\n                        if ($httpResponse['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {\n                            $data = $degzdata;\n                            if ($debug) {\n                                $this->getLogger()->debug(\"---INFLATED RESPONSE---[\" . strlen($data) . \" chars]---\\n$data\\n---END---\");\n                            }\n                        } elseif ($httpResponse['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10))) {\n                            $data = $degzdata;\n                            if ($debug) {","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/phpxmlrpc/src/Helper/Http.php#L206-L242","documentation":"Internal error key used by phpxmlrpc's Http helper (Helper/Http.php, around line 224) when manual de-chunking of an HTTP response body fails. When the response was not handled by CURL, the helper re-implements transfer decoding itself; if the chunked-encoded body is malformed or truncated and cannot be de-chunked, the code sets/raises this 'dechunk_fail' error instead of returning garbage. It signals a corrupt HTTP response body received from the server.","triggerScenarios":"HTTP/1.1 response with 'Transfer-Encoding: chunked' whose body ends prematurely (connection cut mid-transfer) or whose chunk-size lines are corrupted so static::decodeChunked() returns false.","commonSituations":"Proxy/load balancer mangling chunked responses, server or intermediary timing out mid-body, HTTP/1.1 keep-alive broken by firewalls, very large responses truncated.","solutions":["Force HTTP/1.0 (curl option CURLOPT_HTTP_VERSION or equivalent transport option) to avoid chunked transfer encoding.","Add 'Accept-Encoding' handling / ask server to send fixed-length content by disabling chunking server-side.","Check intermediary proxies/CDNs that may truncate chunked bodies; bypass them to test.","Retry the request — transient truncation may succeed on a second attempt."],"exampleFix":"// before\n$client->setOption(CurlClient::OPT_CURL_HANDLE, ...); // default HTTP/1.1\n// after\n$ch = curl_init();\ncurl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // avoid chunked\n$client->setOption(CurlClient::OPT_CURL_HANDLE, $ch);","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { $resp = $client->send($msg); } catch (\\PhpXmlRpc\\Exception\\HttpException $e) { if ($e->getCode() === PhpXmlRpc::$xmlrpcerr['dechunk_fail']) { /* retry once, or force HTTP/1.0 */ } throw $e; }","preventionTips":["Avoid intermediaries known to break chunked responses.","Use HTTP/1.0 or fixed-length responses where possible.","Set sensible timeouts so bodies are not truncated mid-transfer."],"tags":["php","http","chunked","network"],"backgroundTag":"unexpected-response-shape","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}