Make "HTTPRequest::curl" dynamic
This commit is contained in:
parent
9d00e4f1bc
commit
2973ed6448
20 changed files with 72 additions and 84 deletions
|
@ -71,12 +71,12 @@ class HTTPRequest
|
|||
* @return CurlResult
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0)
|
||||
public function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0)
|
||||
{
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
if (strlen($url) > 1000) {
|
||||
Logger::log('URL is longer than 1000 characters. Callstack: ' . System::callstack(20), Logger::DEBUG);
|
||||
$this->logger->debug('URL is longer than 1000 characters.', ['url' => $url, 'callstack' => System::callstack(20)]);
|
||||
return CurlResult::createErrorCurl(substr($url, 0, 200));
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ class HTTPRequest
|
|||
$url = Network::unparseURL($parts);
|
||||
|
||||
if (Network::isUrlBlocked($url)) {
|
||||
Logger::log('domain of ' . $url . ' is blocked', Logger::DATA);
|
||||
$this->logger->info('Domain is blocked.', ['url' => $url]);
|
||||
return CurlResult::createErrorCurl($url);
|
||||
}
|
||||
|
||||
|
@ -128,9 +128,9 @@ class HTTPRequest
|
|||
}
|
||||
|
||||
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
@curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
|
||||
@curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
|
||||
|
||||
$range = intval(DI::config()->get('system', 'curl_range_bytes', 0));
|
||||
$range = intval($this->config->get('system', 'curl_range_bytes', 0));
|
||||
|
||||
if ($range > 0) {
|
||||
@curl_setopt($ch, CURLOPT_RANGE, '0-' . $range);
|
||||
|
@ -152,33 +152,33 @@ class HTTPRequest
|
|||
if (!empty($opts['timeout'])) {
|
||||
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
|
||||
} else {
|
||||
$curl_time = DI::config()->get('system', 'curl_timeout', 60);
|
||||
$curl_time = $this->config->get('system', 'curl_timeout', 60);
|
||||
@curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
|
||||
}
|
||||
|
||||
// by default we will allow self-signed certs
|
||||
// but you can override this
|
||||
|
||||
$check_cert = DI::config()->get('system', 'verifyssl');
|
||||
$check_cert = $this->config->get('system', 'verifyssl');
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
|
||||
|
||||
if ($check_cert) {
|
||||
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
|
||||
}
|
||||
|
||||
$proxy = DI::config()->get('system', 'proxy');
|
||||
$proxy = $this->config->get('system', 'proxy');
|
||||
|
||||
if (strlen($proxy)) {
|
||||
if (!empty($proxy)) {
|
||||
@curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
|
||||
@curl_setopt($ch, CURLOPT_PROXY, $proxy);
|
||||
$proxyuser = @DI::config()->get('system', 'proxyuser');
|
||||
$proxyuser = $this->config->get('system', 'proxyuser');
|
||||
|
||||
if (strlen($proxyuser)) {
|
||||
if (!empty($proxyuser)) {
|
||||
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
|
||||
}
|
||||
}
|
||||
|
||||
if (DI::config()->get('system', 'ipv4_resolve', false)) {
|
||||
if ($this->config->get('system', 'ipv4_resolve', false)) {
|
||||
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
}
|
||||
|
||||
|
@ -204,14 +204,14 @@ class HTTPRequest
|
|||
|
||||
if ($curlResponse->isRedirectUrl()) {
|
||||
$redirects++;
|
||||
Logger::log('curl: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl());
|
||||
$this->logger->notice('Curl redirect.', ['url' => $url, 'to' => $curlResponse->getRedirectUrl()]);
|
||||
@curl_close($ch);
|
||||
return self::curl($curlResponse->getRedirectUrl(), $binary, $opts, $redirects);
|
||||
}
|
||||
|
||||
@curl_close($ch);
|
||||
|
||||
DI::profiler()->saveTimestamp($stamp1, 'network', System::callstack());
|
||||
$this->profiler->saveTimestamp($stamp1, 'network', System::callstack());
|
||||
|
||||
return $curlResponse;
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ class Probe
|
|||
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]);
|
||||
$xrd = null;
|
||||
|
||||
$curlResult = HTTPRequest::curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
|
||||
$curlResult = DI::httpRequest()->curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
|
||||
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
||||
if ($curlResult->isSuccess()) {
|
||||
$xml = $curlResult->getBody();
|
||||
|
@ -183,7 +183,7 @@ class Probe
|
|||
}
|
||||
|
||||
if (!is_object($xrd) && !empty($url)) {
|
||||
$curlResult = HTTPRequest::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
|
||||
$curlResult = DI::httpRequest()->curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']);
|
||||
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
|
||||
if ($curlResult->isTimeout()) {
|
||||
Logger::info('Probing timeout', ['url' => $url]);
|
||||
|
@ -427,7 +427,7 @@ class Probe
|
|||
*/
|
||||
private static function getHideStatus($url)
|
||||
{
|
||||
$curlResult = HTTPRequest::curl($url);
|
||||
$curlResult = DI::httpRequest()->curl($url);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -841,7 +841,7 @@ class Probe
|
|||
|
||||
public static function pollZot($url, $data)
|
||||
{
|
||||
$curlResult = HTTPRequest::curl($url);
|
||||
$curlResult = DI::httpRequest()->curl($url);
|
||||
if ($curlResult->isTimeout()) {
|
||||
return $data;
|
||||
}
|
||||
|
@ -938,7 +938,7 @@ class Probe
|
|||
{
|
||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
|
||||
|
||||
$curlResult = HTTPRequest::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
|
||||
$curlResult = DI::httpRequest()->curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::$istimeout = true;
|
||||
return [];
|
||||
|
@ -1007,7 +1007,7 @@ class Probe
|
|||
*/
|
||||
private static function pollNoscrape($noscrape_url, $data)
|
||||
{
|
||||
$curlResult = HTTPRequest::curl($noscrape_url);
|
||||
$curlResult = DI::httpRequest()->curl($noscrape_url);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::$istimeout = true;
|
||||
return [];
|
||||
|
@ -1265,7 +1265,7 @@ class Probe
|
|||
*/
|
||||
private static function pollHcard($hcard_url, $data, $dfrn = false)
|
||||
{
|
||||
$curlResult = HTTPRequest::curl($hcard_url);
|
||||
$curlResult = DI::httpRequest()->curl($hcard_url);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::$istimeout = true;
|
||||
return [];
|
||||
|
@ -1519,7 +1519,7 @@ class Probe
|
|||
$pubkey = substr($pubkey, 5);
|
||||
}
|
||||
} elseif (Strings::normaliseLink($pubkey) == 'http://') {
|
||||
$curlResult = HTTPRequest::curl($pubkey);
|
||||
$curlResult = DI::httpRequest()->curl($pubkey);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::$istimeout = true;
|
||||
return $short ? false : [];
|
||||
|
@ -1552,7 +1552,7 @@ class Probe
|
|||
}
|
||||
|
||||
// Fetch all additional data from the feed
|
||||
$curlResult = HTTPRequest::curl($data["poll"]);
|
||||
$curlResult = DI::httpRequest()->curl($data["poll"]);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::$istimeout = true;
|
||||
return [];
|
||||
|
@ -1604,7 +1604,7 @@ class Probe
|
|||
*/
|
||||
private static function pumpioProfileData($profile_link)
|
||||
{
|
||||
$curlResult = HTTPRequest::curl($profile_link);
|
||||
$curlResult = DI::httpRequest()->curl($profile_link);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
return [];
|
||||
}
|
||||
|
@ -1835,7 +1835,7 @@ class Probe
|
|||
*/
|
||||
private static function feed($url, $probe = true)
|
||||
{
|
||||
$curlResult = HTTPRequest::curl($url);
|
||||
$curlResult = DI::httpRequest()->curl($url);
|
||||
if ($curlResult->isTimeout()) {
|
||||
self::$istimeout = true;
|
||||
return [];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue