Skip to content

Commit b796163

Browse files
Igor ToropovIgor Toropov
Igor Toropov
authored and
Igor Toropov
committed
fix search progress headers
1 parent be18663 commit b796163

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/Transport/Http.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,43 +418,53 @@ public function getConnectTimeOut(): int
418418
}
419419

420420

421+
/**
422+
* @param $handle
423+
*
424+
* @return bool
425+
*/
421426
public function __findXClickHouseProgress($handle): bool
422427
{
423-
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
428+
$code = (int)curl_getinfo($handle, CURLINFO_HTTP_CODE);
424429

425430
// Search X-ClickHouse-Progress
426-
if ($code == 200) {
431+
if ($code === 200) {
427432
$response = curl_multi_getcontent($handle);
428-
$header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
429-
if (!$header_size) {
433+
$headerSize = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
434+
if (!$headerSize) {
430435
return false;
431436
}
432437

433-
$header = substr($response, 0, $header_size);
434-
if (!$header_size) {
438+
$header = substr($response, 0, $headerSize);
439+
if (!$header) {
435440
return false;
436441
}
437442

438-
$pos = strrpos($header, 'X-ClickHouse-Summary:');
439-
if (!$pos) {
443+
$headerKeys = ['X-ClickHouse-Progress:', 'X-ClickHouse-Summary:'];
444+
foreach ($headerKeys as $headerKey) {
445+
$position = strrpos($header, $headerKey);
446+
447+
if (false !== $position) {
448+
break;
449+
}
450+
}
451+
452+
if (false === $position) {
440453
return false;
441454
}
442455

443-
$last = substr($header, $pos);
444-
$data = @json_decode(str_ireplace('X-ClickHouse-Summary:', '', $last), true);
456+
$last = substr($header, $position);
457+
$data = @json_decode(str_ireplace($headerKey, '', $last), true);
445458

446459
if ($data && is_callable($this->xClickHouseProgress)) {
447-
448460
if (is_array($this->xClickHouseProgress)) {
449461
call_user_func_array($this->xClickHouseProgress, [$data]);
450462
} else {
451463
call_user_func($this->xClickHouseProgress, $data);
452464
}
453-
454-
455465
}
456-
457466
}
467+
458468
return false;
459469
}
460470

0 commit comments

Comments
 (0)