add clear

This commit is contained in:
2020-11-16 16:24:10 +08:00
parent 30b5ea5d3d
commit f7d401b852
+54 -55
View File
@@ -11,31 +11,31 @@ use Swoole\Coroutine\Client;
class HttpClient
{
private string $host = '';
private $host = '';
private array $header = [];
private $header = [];
private int $timeout = 0;
private $timeout = 0;
private ?\Closure $callback = null;
private string $method = 'get';
private $callback = null;
private $method = 'get';
private bool $isSSL = false;
private string $agent = '';
private string $errorCodeField = '';
private string $errorMsgField = '';
private bool $use_swoole = false;
private $isSSL = false;
private $agent = '';
private $errorCodeField = '';
private $errorMsgField = '';
private $use_swoole = false;
private string $ssl_cert_file = '';
private string $ssl_key_file = '';
private string $ca = '';
private int $port = 80;
private $ssl_cert_file = '';
private $ssl_key_file = '';
private $ca = '';
private $port = 80;
/** @var string $_message 错误信息 */
private string $_message = '';
private ?string $_data = '';
/** @var $_message 错误信息 */
private $_message = '';
private $_data = '';
private int $connect_timeout = 1;
private $connect_timeout = 1;
const GET = 'get';
const PUT = 'put';
@@ -46,15 +46,15 @@ class HttpClient
/**
* @return int
*/
public function getConnectTimeout(): int
public function getConnectTimeout()
{
return $this->connect_timeout;
}
/**
* @param int $connect_timeout
* @param $connect_timeout
*/
public function setConnectTimeout(int $connect_timeout): void
public function setConnectTimeout($connect_timeout)
{
$this->connect_timeout = $connect_timeout;
}
@@ -63,15 +63,15 @@ class HttpClient
/**
* @return string
*/
public function getCa(): string
public function getCa()
{
return $this->ca;
}
/**
* @param string $ca
* @param $ca
*/
public function setCa(string $ca): void
public function setCa($ca)
{
$this->ca = $ca;
}
@@ -80,15 +80,15 @@ class HttpClient
/**
* @return int
*/
public function getPort(): int
public function getPort()
{
return $this->port;
}
/**
* @param int $port
* @param $port
*/
public function setPort(int $port): void
public function setPort($port)
{
$this->port = $port;
}
@@ -105,7 +105,7 @@ class HttpClient
/**
* @return string
*/
public function getSslCertFile(): string
public function getSslCertFile()
{
return $this->ssl_cert_file;
}
@@ -127,9 +127,9 @@ class HttpClient
}
/**
* @param string $ssl_cert_file
* @param $ssl_cert_file
*/
public function setSslCertFile(string $ssl_cert_file)
public function setSslCertFile($ssl_cert_file)
{
$this->ssl_cert_file = $ssl_cert_file;
}
@@ -137,15 +137,15 @@ class HttpClient
/**
* @return string
*/
public function getSslKeyFile(): string
public function getSslKeyFile()
{
return $this->ssl_key_file;
}
/**
* @param string $ssl_key_file
* @param $ssl_key_file
*/
public function setSslKeyFile(string $ssl_key_file)
public function setSslKeyFile($ssl_key_file)
{
$this->ssl_key_file = $ssl_key_file;
}
@@ -158,10 +158,10 @@ class HttpClient
}
/**
* @param string $name
* @param $name
* @return $this
*/
public function setErrorField(string $name)
public function setErrorField($name)
{
$this->errorCodeField = $name;
return $this;
@@ -181,19 +181,19 @@ class HttpClient
}
/**
* @param string $name
* @param $name
* @return $this
*/
public function setErrorMsgField(string $name)
public function setErrorMsgField($name)
{
$this->errorMsgField = $name;
return $this;
}
/**
* @param string $host
* @param $host
*/
public function setHost(string $host)
public function setHost($host)
{
var_dump($host);
$this->host = $this->replaceHost($host);
@@ -207,7 +207,7 @@ class HttpClient
/**
* @param $path
* @param array $data
* @param int $type
* @param $type
* @return Result
*/
public function sendTo($path, array $data, $type = SWOOLE_TCP)
@@ -234,10 +234,10 @@ class HttpClient
}
/**
* @param int $sec
* @param $sec
* 设置超时时间
*/
public function setTimeout(int $sec)
public function setTimeout($sec)
{
$this->timeout = $sec;
}
@@ -270,17 +270,17 @@ class HttpClient
}
/**
* @param string $method
* @param $method
*/
public function setMethod(string $method)
public function setMethod($method)
{
$this->method = $method;
}
/**
* @param string $agent
* @param $agent
*/
public function setAgent(string $agent)
public function setAgent($agent)
{
$this->agent = $agent;
}
@@ -329,35 +329,35 @@ class HttpClient
}
/**
* @param string $string
* @param $string
* @return bool|string
* @throws Exception
*/
private function matchHost($string = '')
private function matchHost($_string = '')
{
if (empty($string)) {
return false;
}
if ($this->isHttp($string)) {
$string = str_replace('http://', '', $string);
$_string = str_replace('http://', '', $string);
$hostAndUrls = explode('/', $string);
$this->host = array_shift($hostAndUrls);
$string = implode('/', $hostAndUrls);
$_string = implode('/', $hostAndUrls);
} else if ($this->isHttps($string)) {
$string = str_replace('https://', '', $string);
$_string = str_replace('https://', '', $string);
$this->setIsSSL(true);
$hostAndUrls = explode('/', $string);
$this->host = array_shift($hostAndUrls);
$string = implode('/', $hostAndUrls);
$_string = implode('/', $hostAndUrls);
} else if (empty($this->host)) {
$hostAndUrls = explode('/', $string);
$this->host = array_shift($hostAndUrls);
$string = implode('/', $hostAndUrls);
$_string = implode('/', $hostAndUrls);
}
if (strpos($this->host, ':') !== false) {
@@ -365,7 +365,6 @@ class HttpClient
}
if (!$this->checkIsIp($this->host) && Coroutine::getuid() > 0) {
var_dump($this->host);
$this->host = System::gethostbyname($this->host);
}
@@ -373,7 +372,7 @@ class HttpClient
throw new Exception('Client Host error.');
}
return $string;
return $_string;
}
/**