add clear

This commit is contained in:
as2252258@163.com
2020-01-07 12:35:04 +08:00
parent 40ac73f40f
commit d586e2aee2
2 changed files with 49 additions and 12 deletions
+48 -9
View File
@@ -252,14 +252,33 @@ class HttpClient
*/
private function parseUrlHost(&$url)
{
if (!empty($this->host)) {
return $this->host;
return $this->parseHost($url);
}
/**
* @param $url
* @return string
*/
private function parseHost(&$url)
{
$host = empty($this->host) ? $url : $this->host;
if ($this->checkIsIp($host)) {
return $host;
}
if ($this->isHttp($url)) {
$url = str_replace('http://', '', $url);
} else if ($this->isHttps($url)) {
$url = str_replace('https://', '', $url);
$host = $this->cutRequestUrl($url);
if ($this->checkIsIp($host)) {
return $host;
}
return System::gethostbyname($host);
}
/**
* @param $url
* @return mixed
*/
private function cutRequestUrl(&$url)
{
$url = $this->replaceHost($url);
$explode = explode('/', $url);
$first = array_shift($explode);
if (strpos($first, ':') !== false) {
@@ -269,10 +288,30 @@ class HttpClient
}
$url = '/' . implode('/', $explode);
}
if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $first)) {
return $first;
return $first;
}
/**
* @param $host
* @return string|string[]
*/
private function replaceHost($host)
{
if ($this->isHttp($host)) {
$host = str_replace('http://', '', $host);
} else if ($this->isHttps($host)) {
$host = str_replace('https://', '', $host);
}
return System::gethostbyname($first);
return $host;
}
/**
* @param $url
* @return false|int
*/
private function checkIsIp($url)
{
return preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $url);
}
/**