This commit is contained in:
2021-05-06 10:49:25 +08:00
parent e9efc14df5
commit bc1c72e4f6
4 changed files with 12 additions and 10 deletions
+4 -4
View File
@@ -10,7 +10,7 @@ declare(strict_types=1);
namespace HttpServer\Client;
use Exception;
use JetBrains\PhpStorm\Pure;
use Swoole\Coroutine\Http\Client as SClient;
/**
@@ -63,7 +63,7 @@ class Client extends ClientAbstracts
}
return $this->fail($client->getStatusCode(), $message, $body, $client->getHeaders());
} catch (\Throwable $exception) {
$this->addError($exception,'rpc');
$this->addError($exception, 'rpc');
return $this->fail(500, $exception->getMessage(), [
'file' => $exception->getFile(),
'line' => $exception->getLine()
@@ -94,7 +94,7 @@ class Client extends ClientAbstracts
}
$client->setHeaders($this->getHeader());
$client->setMethod(strtoupper($this->getMethod()));
if (strtolower($this->getMethod()) == self::GET && !empty($data)) {
if ($this->isGet() && !empty($data)) {
$path .= '?' . $data;
} else {
$this->setData($this->mergeParams($data));
@@ -111,7 +111,7 @@ class Client extends ClientAbstracts
/**
* @return array
*/
private function settings(): array
#[Pure] private function settings(): array
{
$sslCert = $this->getSslCertFile();
$sslKey = $this->getSslKeyFile();
+2 -2
View File
@@ -19,10 +19,10 @@ class Curl extends ClientAbstracts
* @param $method
* @param $path
* @param array $params
* @return Result|bool|array|string
* @return Result|array|string
* @throws Exception
*/
public function request($method, $path, $params = []): Result|bool|array|string
public function request($method, $path, $params = []): Result|array|string
{
if ($method == self::GET) {
$path = $this->joinGetParams($path, $params);
+5 -3
View File
@@ -4,7 +4,8 @@
namespace HttpServer\Client;
use Exception;
use JetBrains\PhpStorm\Pure;
use Snowflake\Abstracts\Component;
use Snowflake\Snowflake;
use Swoole\Coroutine;
@@ -22,16 +23,17 @@ class HttpClient extends Component
*/
public static function NewRequest(): IClient
{
return Coroutine::getCid() > 0 ? Client::NewRequest() : Curl::NewRequest();
return Coroutine::getCid() > -1 ? Client::NewRequest() : Curl::NewRequest();
}
/**
* @return Http2
* @throws Exception
*/
public static function http2(): Http2
{
return Snowflake::app()->http2;
return Snowflake::app()->get('http2');
}
}