From a6fc9cd32e2e1f5873c53d7ddaabdbfb4a455795 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 10 Oct 2020 21:07:17 +0200 Subject: [PATCH] Remove $binary flag for HTTPRequest::get(), HTTPRequest::fetch(), HTTPRequest::fetchAll() (deprecated since PHP 5.1.3) --- mod/parse_url.php | 2 +- src/Content/OEmbed.php | 2 +- src/Content/Text/BBCode.php | 2 +- src/Core/Search.php | 4 ++-- src/Core/Worker.php | 2 +- src/Model/GServer.php | 10 +++++----- src/Model/Photo.php | 2 +- src/Model/User.php | 2 +- src/Module/Magic.php | 2 +- src/Network/HTTPRequest.php | 18 ++++++------------ src/Network/IHTTPRequest.php | 9 +++------ src/Network/Probe.php | 6 +++--- src/Protocol/OStatus.php | 4 ++-- src/Util/HTTPSignature.php | 2 +- src/Util/Images.php | 2 +- src/Worker/OnePoll.php | 2 +- 16 files changed, 31 insertions(+), 40 deletions(-) diff --git a/mod/parse_url.php b/mod/parse_url.php index a1faab6efb..ede557ff22 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -85,7 +85,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 = DI::httpRequest()->get($url, false, ['novalidate' => true, 'nobody' => true]); + $curlResponse = DI::httpRequest()->get($url, ['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 30a113f461..4233a2aad7 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -95,7 +95,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery - $html_text = DI::httpRequest()->fetch($embedurl, false, 15, 'text/*'); + $html_text = DI::httpRequest()->fetch($embedurl, 15, 'text/*'); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 594cd9a6ce..e241abadc8 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -485,7 +485,7 @@ class BBCode continue; } - $curlResult = DI::httpRequest()->get($mtch[1], true); + $curlResult = DI::httpRequest()->get($mtch[1]); if (!$curlResult->isSuccess()) { continue; } diff --git a/src/Core/Search.php b/src/Core/Search.php index 7f9ffeec5d..aedad2f0e1 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -122,7 +122,7 @@ class Search $searchUrl .= '&page=' . $page; } - $resultJson = DI::httpRequest()->fetch($searchUrl, false, 0, 'application/json'); + $resultJson = DI::httpRequest()->fetch($searchUrl, 0, 'application/json'); $results = json_decode($resultJson, true); @@ -264,7 +264,7 @@ class Search $return = Contact::searchByName($search, $mode); } else { $p = $page > 1 ? 'p=' . $page : ''; - $curlResult = DI::httpRequest()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), false, ['accept_content' => 'application/json']); + $curlResult = DI::httpRequest()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), ['accept_content' => 'application/json']); if ($curlResult->isSuccess()) { $searchResult = json_decode($curlResult->getBody(), true); if (!empty($searchResult['profiles'])) { diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 09cf14e5af..9af219e476 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1064,7 +1064,7 @@ class Worker } $url = DI::baseUrl() . '/worker'; - DI::httpRequest()->fetch($url, false, 1); + DI::httpRequest()->fetch($url, 1); } /** diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 323a23f494..009816d818 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -311,7 +311,7 @@ class GServer // When a nodeinfo is present, we don't need to dig further $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpRequest()->get($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]); + $curlResult = DI::httpRequest()->get($url . '/.well-known/nodeinfo', ['timeout' => $xrd_timeout]); if ($curlResult->isTimeout()) { self::setFailure($url); return false; @@ -344,7 +344,7 @@ class GServer $basedata = ['detection-method' => self::DETECT_MANUAL]; } - $curlResult = DI::httpRequest()->get($baseurl, false, ['timeout' => $xrd_timeout]); + $curlResult = DI::httpRequest()->get($baseurl, ['timeout' => $xrd_timeout]); if ($curlResult->isSuccess()) { $basedata = self::analyseRootHeader($curlResult, $basedata); $basedata = self::analyseRootBody($curlResult, $basedata, $baseurl); @@ -361,7 +361,7 @@ class GServer // When the base path doesn't seem to contain a social network we try the complete path. // Most detectable system have to be installed in the root directory. // We checked the base to avoid false positives. - $curlResult = DI::httpRequest()->get($url, false, ['timeout' => $xrd_timeout]); + $curlResult = DI::httpRequest()->get($url, ['timeout' => $xrd_timeout]); if ($curlResult->isSuccess()) { $urldata = self::analyseRootHeader($curlResult, $serverdata); $urldata = self::analyseRootBody($curlResult, $urldata, $url); @@ -913,7 +913,7 @@ class GServer private static function validHostMeta(string $url) { $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpRequest()->get($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]); + $curlResult = DI::httpRequest()->get($url . '/.well-known/host-meta', ['timeout' => $xrd_timeout]); if (!$curlResult->isSuccess()) { return false; } @@ -1639,7 +1639,7 @@ class GServer if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $curlResult = DI::httpRequest()->get($api, false, ['headers' => $header]); + $curlResult = DI::httpRequest()->get($api, ['headers' => $header]); if ($curlResult->isSuccess()) { $servers = json_decode($curlResult->getBody(), true); diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 6380f42789..db63f6c596 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -422,7 +422,7 @@ class Photo $filename = basename($image_url); if (!empty($image_url)) { - $ret = DI::httpRequest()->get($image_url, true); + $ret = DI::httpRequest()->get($image_url); $img_str = $ret->getBody(); $type = $ret->getContentType(); } else { diff --git a/src/Model/User.php b/src/Model/User.php index 68c42e40e0..eda724efc7 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1002,7 +1002,7 @@ class User $photo_failure = false; $filename = basename($photo); - $curlResult = DI::httpRequest()->get($photo, true); + $curlResult = DI::httpRequest()->get($photo); if ($curlResult->isSuccess()) { $img_str = $curlResult->getBody(); $type = $curlResult->getContentType(); diff --git a/src/Module/Magic.php b/src/Module/Magic.php index 95b742bb30..fc37d91b45 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -100,7 +100,7 @@ class Magic extends BaseModule ); // Try to get an authentication token from the other instance. - $curlResult = DI::httpRequest()->get($basepath . '/owa', false, ['headers' => $headers]); + $curlResult = DI::httpRequest()->get($basepath . '/owa', ['headers' => $headers]); if ($curlResult->isSuccess()) { $j = json_decode($curlResult->getBody(), true); diff --git a/src/Network/HTTPRequest.php b/src/Network/HTTPRequest.php index e4ff041039..6442295273 100644 --- a/src/Network/HTTPRequest.php +++ b/src/Network/HTTPRequest.php @@ -59,7 +59,7 @@ class HTTPRequest implements IHTTPRequest * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function get(string $url, bool $binary = false, array $opts = [], int &$redirects = 0) + public function get(string $url, array $opts = [], int &$redirects = 0) { $stamp1 = microtime(true); @@ -172,12 +172,7 @@ class HTTPRequest implements IHTTPRequest curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); } - if ($binary) { - @curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); - } - - // don't let curl abort the entire application - // if it throws any errors. + $logger = $this->logger; $s = @curl_exec($ch); $curl_info = @curl_getinfo($ch); @@ -196,7 +191,7 @@ class HTTPRequest implements IHTTPRequest $redirects++; $this->logger->notice('Curl redirect.', ['url' => $url, 'to' => $curlResponse->getRedirectUrl()]); @curl_close($ch); - return $this->get($curlResponse->getRedirectUrl(), $binary, $opts, $redirects); + return $this->get($curlResponse->getRedirectUrl(), $opts, $redirects); } @curl_close($ch); @@ -435,9 +430,9 @@ class HTTPRequest implements IHTTPRequest * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function fetch(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) + public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) { - $ret = $this->fetchFull($url, $binary, $timeout, $accept_content, $cookiejar, $redirects); + $ret = $this->fetchFull($url, $timeout, $accept_content, $cookiejar, $redirects); return $ret->getBody(); } @@ -449,11 +444,10 @@ class HTTPRequest implements IHTTPRequest * * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public function fetchFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) + public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '', int &$redirects = 0) { return $this->get( $url, - $binary, [ 'timeout' => $timeout, 'accept_content' => $accept_content, diff --git a/src/Network/IHTTPRequest.php b/src/Network/IHTTPRequest.php index 3ebcc5dc1b..d6bf981052 100644 --- a/src/Network/IHTTPRequest.php +++ b/src/Network/IHTTPRequest.php @@ -34,7 +34,6 @@ interface IHTTPRequest * to preserve cookies from one request to the next. * * @param string $url URL to fetch - * @param bool $binary default false * TRUE if asked to return binary results (file download) * @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 @@ -42,7 +41,7 @@ interface IHTTPRequest * * @return string The fetched content */ - public function fetch(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = ''); + public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = ''); /** * Fetches the whole response of an URL. @@ -51,7 +50,6 @@ interface IHTTPRequest * all the information collected during the fetch. * * @param string $url URL to fetch - * @param bool $binary default false * TRUE if asked to return binary results (file download) * @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 @@ -59,13 +57,12 @@ interface IHTTPRequest * * @return CurlResult With all relevant information, 'body' contains the actual fetched content. */ - public function fetchFull(string $url, bool $binary = false, int $timeout = 0, string $accept_content = '', string $cookiejar = ''); + public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = ''); /** * Send a GET to an URL. * * @param string $url URL to fetch - * @param bool $binary default false * TRUE if asked to return binary results (file download) * @param array $opts (optional parameters) assoziative array with: * 'accept_content' => supply Accept: header with 'accept_content' as the value @@ -78,7 +75,7 @@ interface IHTTPRequest * * @return CurlResult */ - public function get(string $url, bool $binary = false, array $opts = []); + public function get(string $url, array $opts = []); /** * Send POST request to an URL diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 3fe035286f..67db29a4f3 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -169,7 +169,7 @@ class Probe Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]); $xrd = null; - $curlResult = DI::httpRequest()->get($ssl_url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $curlResult = DI::httpRequest()->get($ssl_url, ['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(); @@ -186,7 +186,7 @@ class Probe } if (!is_object($xrd) && !empty($url)) { - $curlResult = DI::httpRequest()->get($url, false, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $curlResult = DI::httpRequest()->get($url, ['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]); @@ -941,7 +941,7 @@ class Probe { $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20); - $curlResult = DI::httpRequest()->get($url, false, ['timeout' => $xrd_timeout, 'accept_content' => $type]); + $curlResult = DI::httpRequest()->get($url, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($curlResult->isTimeout()) { self::$istimeout = true; return []; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 0635be87d1..4b67d8ecb2 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -738,7 +738,7 @@ class OStatus self::$conv_list[$conversation] = true; - $curlResult = DI::httpRequest()->get($conversation, false, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = DI::httpRequest()->get($conversation, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; @@ -931,7 +931,7 @@ class OStatus } $stored = false; - $curlResult = DI::httpRequest()->get($related, false, ['accept_content' => 'application/atom+xml, text/html']); + $curlResult = DI::httpRequest()->get($related, ['accept_content' => 'application/atom+xml, text/html']); if (!$curlResult->isSuccess()) { return; diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index cdee48bfc0..e3ed5d0799 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -449,7 +449,7 @@ class HTTPSignature $curl_opts = $opts; $curl_opts['header'] = $headers; - $curlResult = DI::httpRequest()->get($request, false, $curl_opts); + $curlResult = DI::httpRequest()->get($request, $curl_opts); $return_code = $curlResult->getReturnCode(); Logger::log('Fetched for user ' . $uid . ' from ' . $request . ' returned ' . $return_code, Logger::DEBUG); diff --git a/src/Util/Images.php b/src/Util/Images.php index f39b0db00d..612a21ed54 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -184,7 +184,7 @@ class Images return $data; } - $img_str = DI::httpRequest()->fetch($url, true, 4); + $img_str = DI::httpRequest()->fetch($url, 4); if (!$img_str) { return []; diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 5fc65b211a..93dff93ae5 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -444,7 +444,7 @@ class OnePoll } $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); - $curlResult = DI::httpRequest()->get($contact['poll'], false, ['cookiejar' => $cookiejar]); + $curlResult = DI::httpRequest()->get($contact['poll'], ['cookiejar' => $cookiejar]); unlink($cookiejar); if ($curlResult->isTimeout()) {