diff --git a/HttpServer/Client/ClientAbstracts.php b/HttpServer/Client/ClientAbstracts.php index 16bb21c9..36a6cc2c 100644 --- a/HttpServer/Client/ClientAbstracts.php +++ b/HttpServer/Client/ClientAbstracts.php @@ -516,7 +516,7 @@ abstract class ClientAbstracts extends Component implements IClient * @param $url * @return bool */ - protected function isHttp($url): bool + #[Pure] protected function isHttp($url): bool { return str_starts_with($url, 'http://'); } @@ -525,7 +525,7 @@ abstract class ClientAbstracts extends Component implements IClient * @param $url * @return bool */ - protected function isHttps($url): bool + #[Pure] protected function isHttps($url): bool { return str_starts_with($url, 'https://'); } @@ -669,7 +669,7 @@ abstract class ClientAbstracts extends Component implements IClient * @return bool * check isPost Request */ - public function isPost(): bool + #[Pure] public function isPost(): bool { return strtolower($this->method) === self::POST; } @@ -680,7 +680,7 @@ abstract class ClientAbstracts extends Component implements IClient * * check isGet Request */ - public function isGet(): bool + #[Pure] public function isGet(): bool { return strtolower($this->method) === self::GET; } @@ -691,7 +691,7 @@ abstract class ClientAbstracts extends Component implements IClient * @return array|string * 将请求参数进行编码 */ - protected function paramEncode($arr): array|string + #[Pure] protected function paramEncode($arr): array|string { if (!is_array($arr)) { return $arr; @@ -757,7 +757,7 @@ abstract class ClientAbstracts extends Component implements IClient * @param $params * @return string */ - protected function joinGetParams($path, $params): string + #[Pure] protected function joinGetParams($path, $params): string { if (empty($params)) { return $path; diff --git a/HttpServer/Client/Curl.php b/HttpServer/Client/Curl.php index cfd7ac8a..b10dd647 100644 --- a/HttpServer/Client/Curl.php +++ b/HttpServer/Client/Curl.php @@ -5,6 +5,7 @@ namespace HttpServer\Client; use Exception; +use JetBrains\PhpStorm\Pure; /** @@ -212,7 +213,7 @@ class Curl extends ClientAbstracts /** * @return array */ - private function parseHeaderMat(): array + #[Pure] private function parseHeaderMat(): array { $headers = []; foreach ($this->getHeader() as $key => $val) { diff --git a/HttpServer/Client/Http2.php b/HttpServer/Client/Http2.php index 7baeaf73..fe2d38c9 100644 --- a/HttpServer/Client/Http2.php +++ b/HttpServer/Client/Http2.php @@ -10,8 +10,8 @@ use Snowflake\Abstracts\Component; use Snowflake\Core\Json; use Snowflake\Core\Xml; use Snowflake\Snowflake; -use Swoole\Http2\Request; use Swoole\Coroutine\Http2\Client as H2Client; +use Swoole\Http2\Request; use Swoole\Http2\Response; @@ -141,7 +141,10 @@ class Http2 extends Component } $client = $this->getClient($domain, $ssl, $timeout); - $request = $this->getRequest($domain, $path, $method, $params, $isUpload); + $request = $this->getRequest($path, $method, $params, $isUpload); + $request->headers = array_merge($request->headers, [ + 'Host' => $domain + ]); $client->send($request); defer(function () use ($domain, $path, $client, $request, $method) { @@ -200,7 +203,6 @@ class Http2 extends Component /** - * @param $domain * @param $path * @param $method * @param $params @@ -208,7 +210,7 @@ class Http2 extends Component * @return Request * @throws Exception */ - public function getRequest($domain, $path, $method, $params, $isUpload = false): Request + public function getRequest($path, $method, $params, $isUpload = false): Request { if (!str_starts_with($path, '/')) { $path = '/' . $path; @@ -245,16 +247,11 @@ class Http2 extends Component $domain = rtrim($domain, '/'); if (str_contains($domain, ':')) { [$domain, $port] = explode(':', $domain); - } else if ($isSsl === true) { - $port = 443; } else { - $port = 80; + $port = $isSsl === true ? 443 : 80; } $client = new H2Client($domain, (int)$port, $isSsl); - $client->set([ - 'timeout' => $timeout, - 'ssl_host_name' => $domain - ]); + $client->set(['timeout' => $timeout, 'ssl_host_name' => $domain]); return $client; }); if ($client->connected && $client->ping()) {