From c76fb40689e2c82ccc7d333124bbca7ac303e9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Thu, 17 Aug 2023 16:32:02 +0800 Subject: [PATCH] qqq --- ClientAbstracts.php | 8 +------- CoroutineClient.php | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ClientAbstracts.php b/ClientAbstracts.php index 42f8caf..f37fba5 100644 --- a/ClientAbstracts.php +++ b/ClientAbstracts.php @@ -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; } diff --git a/CoroutineClient.php b/CoroutineClient.php index 288acff..397d9c0 100644 --- a/CoroutineClient.php +++ b/CoroutineClient.php @@ -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,