This commit is contained in:
2023-08-17 16:32:02 +08:00
parent 18b44b32f2
commit c76fb40689
2 changed files with 8 additions and 7 deletions
+1 -7
View File
@@ -327,15 +327,9 @@ abstract class ClientAbstracts implements IClient
* @param string $host
* @return ClientAbstracts
*/
private function withHost(string $host): static
protected function withHost(string $host): static
{
$this->host = $host;
if (!preg_match('/(\d{1,3}\.){3}\d{1,3}/', $host)) {
if (class_exists(Coroutine::class) && Coroutine::getCid() > -1) {
$this->host = System::gethostbyname($host);
}
return $this->withAddedHeader('Host', $host);
}
return $this;
}
+7
View File
@@ -10,7 +10,9 @@ declare(strict_types=1);
namespace Kiri;
use Exception;
use Swoole\Coroutine;
use Swoole\Coroutine\Http\Client as SwowClient;
use Swoole\Coroutine\System;
/**
* Class Client
@@ -33,6 +35,11 @@ class CoroutineClient extends ClientAbstracts
if (!str_starts_with($path, '/')) {
$path = '/' . $path;
}
$host = $this->getHost();
if (!preg_match('/(\d{1,3}\.){3}\d{1,3}/', $host)) {
$this->withHost(System::gethostbyname($host));
$this->withAddedHeader('Host', $host);
}
$this->withMethod($method)
->coroutine(
$path,