From 19a2b70efd0f48cf204942a447cfbdeaface87f2 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 15 Dec 2022 13:27:28 +0200 Subject: [PATCH] fixed progressFunction --- src/Transport/Http.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Transport/Http.php b/src/Transport/Http.php index 2aa525e..d1c5415 100644 --- a/src/Transport/Http.php +++ b/src/Transport/Http.php @@ -444,29 +444,23 @@ public function __findXClickHouseProgress($handle): bool } $header = substr($response, 0, $header_size); - if (!$header_size) { - return false; - } - - $pos = strrpos($header, 'X-ClickHouse-Summary:'); - if (!$pos) { + if (!$header) { return false; } - $last = substr($header, $pos); - $data = @json_decode(str_ireplace('X-ClickHouse-Summary:', '', $last), true); + $match = []; + if (preg_match_all('/^X-ClickHouse-(?:Progress|Summary):(.*?)$/im', $header, $match)) { + $data = @json_decode(end($match[1]), true); + if ($data && is_callable($this->xClickHouseProgress)) { - if ($data && is_callable($this->xClickHouseProgress)) { + if (is_array($this->xClickHouseProgress)) { + call_user_func_array($this->xClickHouseProgress, [$data]); + } else { + call_user_func($this->xClickHouseProgress, $data); + } - if (is_array($this->xClickHouseProgress)) { - call_user_func_array($this->xClickHouseProgress, [$data]); - } else { - call_user_func($this->xClickHouseProgress, $data); } - - } - } return false; }