diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 7b1171ba41..7da872f0d0 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -209,7 +209,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) * */ - $res = Network::post($dfrn_confirm, $params, null, $redirects, 120)->getBody(); + $res = Network::post($dfrn_confirm, $params, null, 120)->getBody(); Logger::log(' Confirm: received data: ' . $res, Logger::DATA); diff --git a/mod/parse_url.php b/mod/parse_url.php index 7631a5a710..6b393932eb 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -70,9 +70,8 @@ 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 - $redirects = 0; // Fetch the header of the URL - $curlResponse = Network::curl($url, false, $redirects, ['novalidate' => true, 'nobody' => true]); + $curlResponse = Network::curl($url, false, ['novalidate' => true, 'nobody' => true]); if ($curlResponse->isSuccess()) { // Convert the header fields into an array diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 7190f1ce0e..94e95e5f51 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -83,8 +83,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery - $redirects = 0; - $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, 'text/*'); + $html_text = Network::fetchUrl($embedurl, false, 15, 'text/*'); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { diff --git a/src/Core/Search.php b/src/Core/Search.php index 48231f0824..e26cc0edc3 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -107,8 +107,7 @@ class Search extends BaseObject $searchUrl .= '&page=' . $page; } - $red = 0; - $resultJson = Network::fetchUrl($searchUrl, false, $red, 0, 'application/json'); + $resultJson = Network::fetchUrl($searchUrl, false, 0, 'application/json'); $results = json_decode($resultJson, true); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 0f4a527f6b..5485470224 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -983,7 +983,7 @@ class Worker } $url = System::baseUrl()."/worker"; - Network::fetchUrl($url, false, $redirects, 1); + Network::fetchUrl($url, false, 1); } /** diff --git a/src/Model/APContact.php b/src/Model/APContact.php index cf1f9b7231..67c714f9af 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -34,7 +34,7 @@ class APContact extends BaseObject $webfinger = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr); - $curlResult = Network::curl($webfinger, false, $redirects, ['accept_content' => 'application/jrd+json,application/json']); + $curlResult = Network::curl($webfinger, false, ['accept_content' => 'application/jrd+json,application/json']); if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { return false; } diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 491ed31cbd..441fe7f157 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -85,7 +85,7 @@ class Magic extends BaseModule ); // Try to get an authentication token from the other instance. - $curlResult = Network::curl($basepath . '/owa', false, $redirects, ['headers' => $headers]); + $curlResult = Network::curl($basepath . '/owa', false, ['headers' => $headers]); if ($curlResult->isSuccess()) { $j = json_decode($curlResult->getBody(), true); diff --git a/src/Network/Probe.php b/src/Network/Probe.php index b0d2630103..00c38a4c12 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -109,12 +109,11 @@ class Probe $url = "http://".$host."/.well-known/host-meta"; $xrd_timeout = Config::get('system', 'xrd_timeout', 20); - $redirects = 0; Logger::log("Probing for ".$host, Logger::DEBUG); $xrd = null; - $curlResult = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $curlResult = Network::curl($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($curlResult->isSuccess()) { $xml = $curlResult->getBody(); $xrd = XML::parseString($xml, false); @@ -122,7 +121,7 @@ class Probe } if (!is_object($xrd)) { - $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($curlResult->isTimeout()) { Logger::log("Probing timeout for " . $url, Logger::DEBUG); self::$istimeout = true; @@ -738,9 +737,8 @@ class Probe private static function webfinger($url, $type) { $xrd_timeout = Config::get('system', 'xrd_timeout', 20); - $redirects = 0; - $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); + $curlResult = Network::curl($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($curlResult->isTimeout()) { self::$istimeout = true; return false; diff --git a/src/Object/Image.php b/src/Object/Image.php index 67413e3c0d..803aa08b38 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -781,7 +781,7 @@ class Image $data = Cache::get($url); if (is_null($data) || !$data || !is_array($data)) { - $img_str = Network::fetchUrl($url, true, $redirects, 4); + $img_str = Network::fetchUrl($url, true, 4); if (!$img_str) { return false; diff --git a/src/Protocol/ActivityPub.php b/src/Protocol/ActivityPub.php index fa63c44d57..8caf7ac64c 100644 --- a/src/Protocol/ActivityPub.php +++ b/src/Protocol/ActivityPub.php @@ -74,7 +74,7 @@ class ActivityPub return HTTPSignature::fetch($url, $uid); } - $curlResult = Network::curl($url, false, $redirects, ['accept_content' => 'application/activity+json, application/ld+json']); + $curlResult = Network::curl($url, false, ['accept_content' => 'application/activity+json, application/ld+json']); if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { return false; } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 81e5c19db8..9fa0ff43af 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -738,7 +738,7 @@ class OStatus self::$conv_list[$conversation] = true; - $curlResult = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = Network::curl($conversation, false, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -931,7 +931,7 @@ class OStatus } $stored = false; - $curlResult = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = Network::curl($related, false, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 5345cb22fc..60bb844226 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -1004,7 +1004,7 @@ class PortableContact $server_url = str_replace("http://", "https://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]); // Quit if there is a timeout. // But we want to make sure to only quit if we are mostly sure that this server url fits. @@ -1021,7 +1021,7 @@ class PortableContact $server_url = str_replace("https://", "http://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $curlResult = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $curlResult = Network::curl($server_url."/.well-known/host-meta", false, ['timeout' => 20]); // Quit if there is a timeout if ($curlResult->isTimeout()) { @@ -1624,7 +1624,7 @@ class PortableContact if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $curlResult = Network::curl($api, false, $redirects, ['headers' => $header]); + $curlResult = Network::curl($api, false, ['headers' => $header]); if ($curlResult->isSuccess()) { $servers = json_decode($curlResult->getBody(), true); diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index e002d5981c..8a058c3b5c 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -455,7 +455,7 @@ class HTTPSignature $curl_opts = $opts; $curl_opts['header'] = $headers; - $curlResult = Network::curl($request, false, $redirects, $curl_opts); + $curlResult = Network::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/Network.php b/src/Util/Network.php index 9e71c80171..b1d072d7e9 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -25,17 +25,17 @@ class Network * @param string $url URL to fetch * @param bool $binary default false * TRUE if asked to return binary results (file download) - * @param int $redirects The recursion counter for internal use - default 0 * @param int $timeout Timeout in seconds, default system config value or 60 seconds * @param string $accept_content supply Accept: header with 'accept_content' as the value * @param string $cookiejar Path to cookie jar file + * @param int $redirects The recursion counter for internal use - default 0 * * @return string The fetched content * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function fetchUrl(string $url, bool $binary = false, int &$redirects = 0, int $timeout = 0, string $accept_content = null, string $cookiejar = '') + public static function fetchUrl(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) { - $ret = self::fetchUrlFull($url, $binary, $redirects, $timeout, $accept_content, $cookiejar); + $ret = self::fetchUrlFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects); return $ret->getBody(); } @@ -50,24 +50,25 @@ class Network * @param string $url URL to fetch * @param bool $binary default false * TRUE if asked to return binary results (file download) - * @param int $redirects The recursion counter for internal use - default 0 * @param int $timeout Timeout in seconds, default system config value or 60 seconds * @param string $accept_content supply Accept: header with 'accept_content' as the value * @param string $cookiejar Path to cookie jar file + * @param int $redirects The recursion counter for internal use - default 0 * * @return CurlResult With all relevant information, 'body' contains the actual fetched content. * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function fetchUrlFull(string $url, bool $binary = false, int &$redirects = 0, int $timeout = 0, string $accept_content = null, string $cookiejar = '') + public static function fetchUrlFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) { return self::curl( $url, $binary, - $redirects, - ['timeout'=>$timeout, - 'accept_content'=>$accept_content, - 'cookiejar'=>$cookiejar - ] + [ + 'timeout' => $timeout, + 'accept_content' => $accept_content, + 'cookiejar' => $cookiejar + ], + $redirects ); } @@ -77,7 +78,6 @@ class Network * @param string $url URL to fetch * @param bool $binary default false * TRUE if asked to return binary results (file download) - * @param int $redirects The recursion counter for internal use - default 0 * @param array $opts (optional parameters) assoziative array with: * 'accept_content' => supply Accept: header with 'accept_content' as the value * 'timeout' => int Timeout in seconds, default system config value or 60 seconds @@ -86,11 +86,12 @@ class Network * 'nobody' => only return the header * 'cookiejar' => path to cookie jar file * 'header' => header array + * @param int $redirects The recursion counter for internal use - default 0 * * @return CurlResult * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function curl(string $url, bool $binary = false, int &$redirects = 0, array $opts = []) + public static function curl(string $url, bool $binary = false, array $opts = [], int &$redirects = 0) { $stamp1 = microtime(true); @@ -227,7 +228,7 @@ class Network $redirects++; Logger::log('curl: redirect ' . $url . ' to ' . $curlResponse->getRedirectUrl()); @curl_close($ch); - return self::curl($curlResponse->getRedirectUrl(), $binary, $redirects, $opts); + return self::curl($curlResponse->getRedirectUrl(), $binary, $opts, $redirects); } @curl_close($ch); @@ -249,7 +250,7 @@ class Network * @return CurlResult The content * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function post(string $url, $params, string $headers = null, int &$redirects = 0, int $timeout = 0) + public static function post(string $url, $params, string $headers = null, int $timeout = 0, int &$redirects = 0) { $stamp1 = microtime(true); diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 8f494af53a..a605ee92ed 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -371,7 +371,7 @@ class OnePoll } $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); - $curlResult = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); + $curlResult = Network::curl($contact['poll'], false, ['cookiejar' => $cookiejar]); unlink($cookiejar); if ($curlResult->isTimeout()) {