add clear
This commit is contained in:
+48
-9
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user