diff --git a/HttpServer/Client/Client.php b/HttpServer/Client/Client.php index 1c321d21..1a295abb 100644 --- a/HttpServer/Client/Client.php +++ b/HttpServer/Client/Client.php @@ -50,6 +50,12 @@ class Client private $connect_timeout = 1; + const GET = 'get'; + const PUT = 'put'; + const POST = 'post'; + const DELETE = 'delete'; + const OPTIONS = 'option'; + /** * @return int */ @@ -100,19 +106,6 @@ class Client $this->port = $port; } - const POST = 'post'; - const GET = 'get'; - const PUT = 'put'; - const DELETE = 'delete'; - const OPTIONS = 'option'; - - /** - * HttpClient constructor. - */ - private function __construct() - { - } - /** * @return Http2 @@ -264,7 +257,6 @@ class Client } $client->close(); return $param; - } /** diff --git a/HttpServer/Client/Http2.php b/HttpServer/Client/Http2.php index 0a42a3ee..a1e11dd2 100644 --- a/HttpServer/Client/Http2.php +++ b/HttpServer/Client/Http2.php @@ -6,6 +6,7 @@ namespace HttpServer\Client; use Exception; use Snowflake\Abstracts\Component; +use Snowflake\Core\Help; use Snowflake\Core\JSON; use Swoole\Http2\Request; use \Swoole\Coroutine\Http2\Client as H2Client; @@ -38,7 +39,7 @@ class Http2 extends Component { $client = $this->getClient($domain, $path, $timeout); $client->send($this->getRequest($domain, $path, 'GET', $params)); - return $client->recv(); + return new Result(['code' => 0, 'data' => Help::toArray($client->recv())]); } @@ -54,7 +55,7 @@ class Http2 extends Component { $client = $this->getClient($domain, $path, $timeout); $client->send($this->getRequest($domain, $path, 'POST', $params)); - return $client->recv(); + return new Result(['code' => 0, 'data' => Help::toArray($client->recv())]); } diff --git a/HttpServer/Client/Result.php b/HttpServer/Client/Result.php index 10cea0df..09b3c23b 100644 --- a/HttpServer/Client/Result.php +++ b/HttpServer/Client/Result.php @@ -28,7 +28,6 @@ class Result extends Application public $requestTime = 0; public $runTime = 0; - public $statusCode = [100, 101, 200, 201, 202, 203, 204, 205, 206]; /** @@ -132,7 +131,7 @@ class Result extends Application */ public function httpIsOk() { - return in_array($this->httpStatus, $this->statusCode); + return in_array($this->httpStatus, [100, 101, 200, 201, 202, 203, 204, 205, 206]); } /** @@ -153,7 +152,6 @@ class Result extends Application case 'application/json'; case 'text/plain'; return json_decode($this->data, true); - break; } return $this->data; } diff --git a/composer.json b/composer.json index 98c4db9a..1cb10470 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-memcached": "*", - "ext-inotify": "*" + "ext-inotify": "*", + "ext-curl": "*" }, "autoload": { "psr-4": {