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;
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;
}
/**
+3 -2
View File
@@ -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())]);
}
+1 -3
View File
@@ -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;
}