This commit is contained in:
2021-04-28 19:05:15 +08:00
parent 1c39bf1f2b
commit 81fdf7e929
3 changed files with 16 additions and 18 deletions
+6 -6
View File
@@ -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;
+2 -1
View File
@@ -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) {
+8 -11
View File
@@ -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()) {