This commit is contained in:
2020-09-11 19:43:19 +08:00
parent afc2eb2e0e
commit b27dacba3b
4 changed files with 12 additions and 20 deletions
+6 -14
View File
@@ -50,6 +50,12 @@ class Client
private $connect_timeout = 1; private $connect_timeout = 1;
const GET = 'get';
const PUT = 'put';
const POST = 'post';
const DELETE = 'delete';
const OPTIONS = 'option';
/** /**
* @return int * @return int
*/ */
@@ -100,19 +106,6 @@ class Client
$this->port = $port; $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 * @return Http2
@@ -264,7 +257,6 @@ class Client
} }
$client->close(); $client->close();
return $param; return $param;
} }
/** /**
+3 -2
View File
@@ -6,6 +6,7 @@ namespace HttpServer\Client;
use Exception; use Exception;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Core\Help;
use Snowflake\Core\JSON; use Snowflake\Core\JSON;
use Swoole\Http2\Request; use Swoole\Http2\Request;
use \Swoole\Coroutine\Http2\Client as H2Client; use \Swoole\Coroutine\Http2\Client as H2Client;
@@ -38,7 +39,7 @@ class Http2 extends Component
{ {
$client = $this->getClient($domain, $path, $timeout); $client = $this->getClient($domain, $path, $timeout);
$client->send($this->getRequest($domain, $path, 'GET', $params)); $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 = $this->getClient($domain, $path, $timeout);
$client->send($this->getRequest($domain, $path, 'POST', $params)); $client->send($this->getRequest($domain, $path, 'POST', $params));
return $client->recv(); return new Result(['code' => 0, 'data' => Help::toArray($client->recv())]);
} }
+1 -3
View File
@@ -28,7 +28,6 @@ class Result extends Application
public $requestTime = 0; public $requestTime = 0;
public $runTime = 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() 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 'application/json';
case 'text/plain'; case 'text/plain';
return json_decode($this->data, true); return json_decode($this->data, true);
break;
} }
return $this->data; return $this->data;
} }
+2 -1
View File
@@ -25,7 +25,8 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-xml": "*", "ext-xml": "*",
"ext-memcached": "*", "ext-memcached": "*",
"ext-inotify": "*" "ext-inotify": "*",
"ext-curl": "*"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {