From 2973ed6448f56dd807df3ec0d20d095226d14b65 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Wed, 4 Mar 2020 22:15:46 +0100 Subject: [PATCH] Make "HTTPRequest::curl" dynamic --- mod/ostatus_subscribe.php | 3 +-- mod/parse_url.php | 3 +-- mod/redir.php | 3 +-- src/Core/Search.php | 2 +- src/Model/GContact.php | 7 +++---- src/Model/GServer.php | 36 ++++++++++++++++---------------- src/Model/Photo.php | 3 +-- src/Model/Profile.php | 3 +-- src/Module/Admin/Summary.php | 3 +-- src/Module/Magic.php | 3 +-- src/Network/HTTPRequest.php | 28 ++++++++++++------------- src/Network/Probe.php | 22 +++++++++---------- src/Protocol/ActivityPub.php | 3 +-- src/Protocol/DFRN.php | 2 +- src/Protocol/OStatus.php | 15 +++++++------ src/Protocol/PortableContact.php | 8 +++---- src/Util/ExAuth.php | 3 +-- src/Util/HTTPSignature.php | 2 +- src/Util/ParseUrl.php | 3 +-- src/Worker/OnePoll.php | 4 ++-- 20 files changed, 72 insertions(+), 84 deletions(-) diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 6b6c94987..5a3a625ce 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -23,7 +23,6 @@ use Friendica\App; use Friendica\Core\Protocol; use Friendica\DI; use Friendica\Model\Contact; -use Friendica\Network\HTTPRequest; function ostatus_subscribe_content(App $a) { @@ -55,7 +54,7 @@ function ostatus_subscribe_content(App $a) $api = $contact['baseurl'] . '/api/'; // Fetching friends - $curlResult = HTTPRequest::curl($api . 'statuses/friends.json?screen_name=' . $contact['nick']); + $curlResult = DI::httpRequest()->curl($api . 'statuses/friends.json?screen_name=' . $contact['nick']); if (!$curlResult->isSuccess()) { DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact'); diff --git a/mod/parse_url.php b/mod/parse_url.php index 49e41246c..0e80d971a 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -28,7 +28,6 @@ use Friendica\Content\PageInfo; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\System; -use Friendica\Network\HTTPRequest; use Friendica\Util\ParseUrl; use Friendica\Util\Strings; @@ -85,7 +84,7 @@ function parse_url_content(App $a) // Check if the URL is an image, video or audio file. If so format // the URL with the corresponding BBCode media tag // Fetch the header of the URL - $curlResponse = HTTPRequest::curl($url, false, ['novalidate' => true, 'nobody' => true]); + $curlResponse = DI::httpRequest()->curl($url, false, ['novalidate' => true, 'nobody' => true]); if ($curlResponse->isSuccess()) { // Convert the header fields into an array diff --git a/mod/redir.php b/mod/redir.php index deb97ca1c..4069518cd 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -27,7 +27,6 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Profile; -use Friendica\Network\HTTPRequest; use Friendica\Util\Strings; function redir_init(App $a) { @@ -171,7 +170,7 @@ function redir_magic($a, $cid, $url) } // Test for magic auth on the target system - $serverret = HTTPRequest::curl($basepath . '/magic'); + $serverret = DI::httpRequest()->curl($basepath . '/magic'); if ($serverret->isSuccess()) { $separator = strpos($target_url, '?') ? '&' : '?'; $target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url); diff --git a/src/Core/Search.php b/src/Core/Search.php index 26af05e74..aafa4024a 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -285,7 +285,7 @@ class Search $return = GContact::searchByName($search, $mode); } else { $p = $page > 1 ? 'p=' . $page : ''; - $curlResult = HTTPRequest::curl(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), false, ['accept_content' => 'application/json']); + $curlResult = DI::httpRequest()->curl(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), false, ['accept_content' => 'application/json']); if ($curlResult->isSuccess()) { $searchResult = json_decode($curlResult->getBody(), true); if (!empty($searchResult['profiles'])) { diff --git a/src/Model/GContact.php b/src/Model/GContact.php index a7cf837bd..669bc60c5 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -36,7 +36,6 @@ use Friendica\Network\Probe; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; -use Friendica\Util\Network; use Friendica\Util\Strings; /** @@ -846,7 +845,7 @@ class GContact return false; } - $curlResult = HTTPRequest::curl($gserver['noscrape'] . '/' . $data['nick']); + $curlResult = DI::httpRequest()->curl($gserver['noscrape'] . '/' . $data['nick']); if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { $noscrape = json_decode($curlResult->getBody(), true); @@ -928,7 +927,7 @@ class GContact private static function updateFromFeed(array $data) { // Search for the newest entry in the feed - $curlResult = HTTPRequest::curl($data['poll']); + $curlResult = DI::httpRequest()->curl($data['poll']); if (!$curlResult->isSuccess()) { $fields = ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()]; DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($data['url'])]); @@ -1206,7 +1205,7 @@ class GContact $url = $server . '/main/statistics'; - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if (!$curlResult->isSuccess()) { return false; } diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 80ef201a8..c868e19d4 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -310,7 +310,7 @@ class GServer // When a nodeinfo is present, we don't need to dig further $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = HTTPRequest::curl($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]); + $curlResult = DI::httpRequest()->curl($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]); if ($curlResult->isTimeout()) { self::setFailure($url); return false; @@ -343,7 +343,7 @@ class GServer $basedata = ['detection-method' => self::DETECT_MANUAL]; } - $curlResult = HTTPRequest::curl($baseurl, false, ['timeout' => $xrd_timeout]); + $curlResult = DI::httpRequest()->curl($baseurl, false, ['timeout' => $xrd_timeout]); if ($curlResult->isSuccess()) { $basedata = self::analyseRootHeader($curlResult, $basedata); $basedata = self::analyseRootBody($curlResult, $basedata, $baseurl); @@ -499,7 +499,7 @@ class GServer { Logger::info('Discover relay data', ['server' => $server_url]); - $curlResult = HTTPRequest::curl($server_url . '/.well-known/x-social-relay'); + $curlResult = DI::httpRequest()->curl($server_url . '/.well-known/x-social-relay'); if (!$curlResult->isSuccess()) { return; } @@ -580,7 +580,7 @@ class GServer */ private static function fetchStatistics(string $url) { - $curlResult = HTTPRequest::curl($url . '/statistics.json'); + $curlResult = DI::httpRequest()->curl($url . '/statistics.json'); if (!$curlResult->isSuccess()) { return []; } @@ -690,7 +690,7 @@ class GServer */ private static function parseNodeinfo1(string $nodeinfo_url) { - $curlResult = HTTPRequest::curl($nodeinfo_url); + $curlResult = DI::httpRequest()->curl($nodeinfo_url); if (!$curlResult->isSuccess()) { return []; @@ -767,7 +767,7 @@ class GServer */ private static function parseNodeinfo2(string $nodeinfo_url) { - $curlResult = HTTPRequest::curl($nodeinfo_url); + $curlResult = DI::httpRequest()->curl($nodeinfo_url); if (!$curlResult->isSuccess()) { return []; } @@ -844,7 +844,7 @@ class GServer */ private static function fetchSiteinfo(string $url, array $serverdata) { - $curlResult = HTTPRequest::curl($url . '/siteinfo.json'); + $curlResult = DI::httpRequest()->curl($url . '/siteinfo.json'); if (!$curlResult->isSuccess()) { return $serverdata; } @@ -913,7 +913,7 @@ class GServer private static function validHostMeta(string $url) { $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = HTTPRequest::curl($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]); + $curlResult = DI::httpRequest()->curl($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]); if (!$curlResult->isSuccess()) { return false; } @@ -1009,7 +1009,7 @@ class GServer { $serverdata['poco'] = ''; - $curlResult = HTTPRequest::curl($url . '/poco'); + $curlResult = DI::httpRequest()->curl($url . '/poco'); if (!$curlResult->isSuccess()) { return $serverdata; } @@ -1039,7 +1039,7 @@ class GServer */ public static function checkMastodonDirectory(string $url, array $serverdata) { - $curlResult = HTTPRequest::curl($url . '/api/v1/directory?limit=1'); + $curlResult = DI::httpRequest()->curl($url . '/api/v1/directory?limit=1'); if (!$curlResult->isSuccess()) { return $serverdata; } @@ -1066,7 +1066,7 @@ class GServer */ private static function detectNextcloud(string $url, array $serverdata) { - $curlResult = HTTPRequest::curl($url . '/status.php'); + $curlResult = DI::httpRequest()->curl($url . '/status.php'); if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) { return $serverdata; @@ -1100,7 +1100,7 @@ class GServer */ private static function detectMastodonAlikes(string $url, array $serverdata) { - $curlResult = HTTPRequest::curl($url . '/api/v1/instance'); + $curlResult = DI::httpRequest()->curl($url . '/api/v1/instance'); if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) { return $serverdata; @@ -1166,7 +1166,7 @@ class GServer */ private static function detectHubzilla(string $url, array $serverdata) { - $curlResult = HTTPRequest::curl($url . '/api/statusnet/config.json'); + $curlResult = DI::httpRequest()->curl($url . '/api/statusnet/config.json'); if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) { return $serverdata; } @@ -1264,7 +1264,7 @@ class GServer private static function detectGNUSocial(string $url, array $serverdata) { // Test for GNU Social - $curlResult = HTTPRequest::curl($url . '/api/gnusocial/version.json'); + $curlResult = DI::httpRequest()->curl($url . '/api/gnusocial/version.json'); if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') && ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) { $serverdata['platform'] = 'gnusocial'; @@ -1282,7 +1282,7 @@ class GServer } // Test for Statusnet - $curlResult = HTTPRequest::curl($url . '/api/statusnet/version.json'); + $curlResult = DI::httpRequest()->curl($url . '/api/statusnet/version.json'); if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') && ($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) { @@ -1318,9 +1318,9 @@ class GServer */ private static function detectFriendica(string $url, array $serverdata) { - $curlResult = HTTPRequest::curl($url . '/friendica/json'); + $curlResult = DI::httpRequest()->curl($url . '/friendica/json'); if (!$curlResult->isSuccess()) { - $curlResult = HTTPRequest::curl($url . '/friendika/json'); + $curlResult = DI::httpRequest()->curl($url . '/friendika/json'); $friendika = true; $platform = 'Friendika'; } else { @@ -1653,7 +1653,7 @@ class GServer if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $curlResult = HTTPRequest::curl($api, false, ['headers' => $header]); + $curlResult = DI::httpRequest()->curl($api, false, ['headers' => $header]); if ($curlResult->isSuccess()) { $servers = json_decode($curlResult->getBody(), true); diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 125718bf5..a10711db2 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -28,7 +28,6 @@ use Friendica\Database\DBA; use Friendica\Database\DBStructure; use Friendica\DI; use Friendica\Model\Storage\SystemResource; -use Friendica\Network\HTTPRequest; use Friendica\Object\Image; use Friendica\Util\DateTimeFormat; use Friendica\Util\Images; @@ -421,7 +420,7 @@ class Photo $filename = basename($image_url); if (!empty($image_url)) { - $ret = HTTPRequest::curl($image_url, true); + $ret = DI::httpRequest()->curl($image_url, true); $img_str = $ret->getBody(); $type = $ret->getContentType(); } else { diff --git a/src/Model/Profile.php b/src/Model/Profile.php index c8fd9d029..d32940ae6 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -33,7 +33,6 @@ use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Network\HTTPRequest; use Friendica\Protocol\Activity; use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; @@ -738,7 +737,7 @@ class Profile $magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request; // We have to check if the remote server does understand /magic without invoking something - $serverret = HTTPRequest::curl($basepath . '/magic'); + $serverret = DI::httpRequest()->curl($basepath . '/magic'); if ($serverret->isSuccess()) { Logger::log('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path, Logger::DEBUG); System::externalRedirect($magic_path); diff --git a/src/Module/Admin/Summary.php b/src/Module/Admin/Summary.php index 6dcef2ea4..ad84bb6ab 100644 --- a/src/Module/Admin/Summary.php +++ b/src/Module/Admin/Summary.php @@ -32,7 +32,6 @@ use Friendica\DI; use Friendica\Model\Register; use Friendica\Module\BaseAdmin; use Friendica\Network\HTTPException\InternalServerErrorException; -use Friendica\Network\HTTPRequest; use Friendica\Util\ConfigFileLoader; use Friendica\Util\DateTimeFormat; @@ -247,7 +246,7 @@ class Summary extends BaseAdmin private static function checkSelfHostMeta() { // Fetch the host-meta to check if this really is a vital server - return HTTPRequest::curl(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess(); + return DI::httpRequest()->curl(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess(); } } diff --git a/src/Module/Magic.php b/src/Module/Magic.php index b65159585..a025617d8 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -27,7 +27,6 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; -use Friendica\Network\HTTPRequest; use Friendica\Util\HTTPSignature; use Friendica\Util\Strings; @@ -101,7 +100,7 @@ class Magic extends BaseModule ); // Try to get an authentication token from the other instance. - $curlResult = HTTPRequest::curl($basepath . '/owa', false, ['headers' => $headers]); + $curlResult = DI::httpRequest()->curl($basepath . '/owa', false, ['headers' => $headers]); if ($curlResult->isSuccess()) { $j = json_decode($curlResult->getBody(), true); diff --git a/src/Network/HTTPRequest.php b/src/Network/HTTPRequest.php index 7d7d59a6d..73e5cd8e0 100644 --- a/src/Network/HTTPRequest.php +++ b/src/Network/HTTPRequest.php @@ -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; } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index dadd794fe..01dc28408 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -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 []; diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index 24c6250a4..f41708011 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -24,7 +24,6 @@ namespace Friendica\Protocol; use Friendica\Core\Protocol; use Friendica\Model\APContact; use Friendica\Model\User; -use Friendica\Network\HTTPRequest; use Friendica\Util\HTTPSignature; use Friendica\Util\JsonLD; @@ -93,7 +92,7 @@ class ActivityPub return HTTPSignature::fetch($url, $uid); } - $curlResult = HTTPRequest::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']); + $curlResult = DI::httpRequest()->curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']); if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { return false; } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 21adc58cc..ef7eb0f48 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1195,7 +1195,7 @@ class DFRN Logger::log('dfrn_deliver: ' . $url); - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if ($curlResult->isTimeout()) { return -2; // timed out diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 779c99358..a9ee2277e 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -39,7 +39,6 @@ use Friendica\Model\Item; use Friendica\Model\ItemURI; use Friendica\Model\Tag; use Friendica\Model\User; -use Friendica\Network\HTTPRequest; use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; use Friendica\Util\Images; @@ -756,7 +755,7 @@ class OStatus self::$conv_list[$conversation] = true; - $curlResult = HTTPRequest::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = DI::httpRequest()->curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -785,7 +784,7 @@ class OStatus } } if ($file != '') { - $conversation_atom = HTTPRequest::curl($attribute['href']); + $conversation_atom = DI::httpRequest()->curl($attribute['href']); if ($conversation_atom->isSuccess()) { $xml = $conversation_atom->getBody(); @@ -902,7 +901,7 @@ class OStatus return; } - $curlResult = HTTPRequest::curl($self); + $curlResult = DI::httpRequest()->curl($self); if (!$curlResult->isSuccess()) { return; @@ -949,7 +948,7 @@ class OStatus } $stored = false; - $curlResult = HTTPRequest::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = DI::httpRequest()->curl($related, false, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -980,7 +979,7 @@ class OStatus } } if ($atom_file != '') { - $curlResult = HTTPRequest::curl($atom_file); + $curlResult = DI::httpRequest()->curl($atom_file); if ($curlResult->isSuccess()) { Logger::log('Fetched XML for URI ' . $related_uri, Logger::DEBUG); @@ -992,7 +991,7 @@ class OStatus // Workaround for older GNU Social servers if (($xml == '') && strstr($related, '/notice/')) { - $curlResult = HTTPRequest::curl(str_replace('/notice/', '/api/statuses/show/', $related) . '.atom'); + $curlResult = DI::httpRequest()->curl(str_replace('/notice/', '/api/statuses/show/', $related) . '.atom'); if ($curlResult->isSuccess()) { Logger::log('GNU Social workaround to fetch XML for URI ' . $related_uri, Logger::DEBUG); @@ -1003,7 +1002,7 @@ class OStatus // Even more worse workaround for GNU Social ;-) if ($xml == '') { $related_guess = self::convertHref($related_uri); - $curlResult = HTTPRequest::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess) . '.atom'); + $curlResult = DI::httpRequest()->curl(str_replace('/notice/', '/api/statuses/show/', $related_guess) . '.atom'); if ($curlResult->isSuccess()) { Logger::log('GNU Social workaround 2 to fetch XML for URI ' . $related_uri, Logger::DEBUG); diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index f2ad51070..0284c9b8a 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -251,7 +251,7 @@ class PortableContact */ private static function fetchServerlist($poco) { - $curlResult = HTTPRequest::curl($poco . "/@server"); + $curlResult = DI::httpRequest()->curl($poco . "/@server"); if (!$curlResult->isSuccess()) { return; @@ -291,7 +291,7 @@ class PortableContact Logger::info("Fetch all users from the server " . $server["url"]); - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { $data = json_decode($curlResult->getBody(), true); @@ -314,7 +314,7 @@ class PortableContact $success = false; - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { Logger::info("Fetch all global contacts from the server " . $server["nurl"]); @@ -372,7 +372,7 @@ class PortableContact // Fetch all contacts from a given user from the other server $url = $server['poco'] . '/' . $username . '/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,contactType,generation'; - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if ($curlResult->isSuccess()) { $data = json_decode($curlResult->getBody(), true); diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 710c00979..593386082 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -37,7 +37,6 @@ namespace Friendica\Util; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\User; -use Friendica\Network\HTTPRequest; class ExAuth { @@ -182,7 +181,7 @@ class ExAuth $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if (!$curlResult->isSuccess()) { return false; diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index 5d57c2281..8c1d4f986 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -443,7 +443,7 @@ class HTTPSignature $curl_opts = $opts; $curl_opts['header'] = $headers; - $curlResult = HTTPRequest::curl($request, false, $curl_opts); + $curlResult = DI::httpRequest()->curl($request, false, $curl_opts); $return_code = $curlResult->getReturnCode(); Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG); diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 577ffd4c1..cf38ffd7b 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -27,7 +27,6 @@ use Friendica\Content\OEmbed; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Database\DBA; -use Friendica\Network\HTTPRequest; /** * Get information about a given URL @@ -160,7 +159,7 @@ class ParseUrl return $siteinfo; } - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if (!$curlResult->isSuccess()) { return $siteinfo; } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 13d1b8ee7..0dc67d80f 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -291,7 +291,7 @@ class OnePoll . '&type=data&last_update=' . $last_update . '&perm=' . $perm; - $curlResult = HTTPRequest::curl($url); + $curlResult = DI::httpRequest()->curl($url); if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) { // set the last-update so we don't keep polling @@ -444,7 +444,7 @@ class OnePoll } $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); - $curlResult = HTTPRequest::curl($contact['poll'], false, ['cookiejar' => $cookiejar]); + $curlResult = DI::httpRequest()->curl($contact['poll'], false, ['cookiejar' => $cookiejar]); unlink($cookiejar); if ($curlResult->isTimeout()) {