From 5751e024c0189c117f496ac9ddf4845c55b8f710 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 12 May 2024 17:53:21 +0000 Subject: [PATCH] Request type set for all HTTP requests --- src/Content/OEmbed.php | 5 +- src/Content/Text/BBCode.php | 4 +- src/Core/Search.php | 6 +- src/Model/GServer.php | 55 ++++++++++--------- src/Model/Item.php | 3 +- src/Model/Post/Media.php | 3 +- src/Model/User.php | 4 +- src/Module/Contact/MatchInterests.php | 5 +- src/Module/Debug/Feed.php | 3 +- src/Module/OStatus/PubSubHubBub.php | 4 +- src/Module/OStatus/Subscribe.php | 4 +- src/Module/Photo.php | 2 +- .../Capability/ICanSendHttpRequests.php | 6 +- src/Network/HTTPClient/Client/HttpClient.php | 11 ++-- .../HTTPClient/Client/HttpClientRequest.php | 29 ++++++---- src/Network/Probe.php | 27 ++++----- src/Protocol/Diaspora.php | 2 +- src/Protocol/OStatus.php | 10 ++-- src/Protocol/Salmon.php | 2 +- src/Security/ExAuth.php | 4 +- src/Util/Images.php | 3 +- src/Util/Network.php | 2 +- src/Util/ParseUrl.php | 2 +- src/Worker/CheckRelMeProfileLink.php | 3 +- src/Worker/Directory.php | 3 +- src/Worker/OnePoll.php | 2 +- src/Worker/PullDirectory.php | 3 +- src/Worker/SearchDirectory.php | 3 +- src/Worker/UpdateServerDirectory.php | 5 +- src/Worker/UpdateServerPeers.php | 4 +- 30 files changed, 129 insertions(+), 90 deletions(-) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 5e6b166234..fb8515eecb 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -32,6 +32,7 @@ use Friendica\Database\Database; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\ParseUrl; @@ -86,7 +87,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery - $html_text = DI::httpClient()->fetch($embedurl, HttpClientAccept::HTML, 15); + $html_text = DI::httpClient()->fetch($embedurl, HttpClientAccept::HTML, 15, '', HttpClientRequest::SITEINFO); if (!empty($html_text)) { $dom = new DOMDocument(); if (@$dom->loadHTML($html_text)) { @@ -100,7 +101,7 @@ class OEmbed // but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯ $href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'], ['https://www.youtube.com/', 'https://player.vimeo.com/'], $href); - $result = DI::httpClient()->fetchFull($href . '&maxwidth=' . $a->getThemeInfoValue('videowidth')); + $result = DI::httpClient()->fetchFull($href . '&maxwidth=' . $a->getThemeInfoValue('videowidth'), HttpClientAccept::DEFAULT, 0, '', HttpClientRequest::SITEINFO); if ($result->isSuccess()) { $json_string = $result->getBodyString(); break; diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 0116ddc8f5..1a9201b5d4 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -974,7 +974,7 @@ class BBCode $text = '[url=' . $match[2] . ']' . $match[2] . '[/url]'; // if its not a picture then look if its a page that contains a picture link - $body = DI::httpClient()->fetch($match[1], HttpClientAccept::HTML, 0); + $body = DI::httpClient()->fetch($match[1], HttpClientAccept::HTML, 0, '', HttpClientRequest::SITEINFO); if (empty($body)) { DI::cache()->set($cache_key, $text); return $text; @@ -1077,7 +1077,7 @@ class BBCode } // if its not a picture then look if its a page that contains a picture link - $body = DI::httpClient()->fetch($match[1], HttpClientAccept::HTML, 0); + $body = DI::httpClient()->fetch($match[1], HttpClientAccept::HTML, 0, '', HttpClientRequest::SITEINFO); if (empty($body)) { DI::cache()->set($cache_key, $text); return $text; diff --git a/src/Core/Search.php b/src/Core/Search.php index db200ed47d..f9785223b5 100644 --- a/src/Core/Search.php +++ b/src/Core/Search.php @@ -24,6 +24,8 @@ namespace Friendica\Core; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\HTTPException; use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ResultList; @@ -125,7 +127,7 @@ class Search $searchUrl .= '&page=' . $page; } - $resultJson = DI::httpClient()->fetch($searchUrl, HttpClientAccept::JSON); + $resultJson = DI::httpClient()->fetch($searchUrl, HttpClientAccept::JSON, 0, '', HttpClientRequest::CONTACTDISCOVER); $results = json_decode($resultJson, true); @@ -232,7 +234,7 @@ class Search $return = Contact::searchByName($search, $mode, true); } else { $p = $page > 1 ? 'p=' . $page : ''; - $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTDISCOVER]); if ($curlResult->isSuccess()) { $searchResult = json_decode($curlResult->getBodyString(), true); if (!empty($searchResult['profiles'])) { diff --git a/src/Model/GServer.php b/src/Model/GServer.php index 060aa77dbf..f4ef38e765 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -34,6 +34,7 @@ use Friendica\Module\Register; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\Probe; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Relay; @@ -611,7 +612,7 @@ class GServer $in_webroot = empty(parse_url($url, PHP_URL_PATH)); // When a nodeinfo is present, we don't need to dig further - $curlResult = DI::httpClient()->get($url . '/.well-known/x-nodeinfo2', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/.well-known/x-nodeinfo2', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if ($curlResult->isTimeout()) { self::setFailureByUrl($url); return false; @@ -622,7 +623,7 @@ class GServer } else { $serverdata = self::parseNodeinfo210($curlResult); if (empty($serverdata)) { - $curlResult = DI::httpClient()->get($url . '/.well-known/nodeinfo', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/.well-known/nodeinfo', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); $serverdata = self::fetchNodeinfo($url, $curlResult); } } @@ -640,9 +641,9 @@ class GServer if ($in_webroot) { // Fetch the landing page, possibly it reveals some data $accept = 'application/activity+json,application/ld+json,application/json,*/*;q=0.9'; - $curlResult = DI::httpClient()->get($url, $accept); + $curlResult = DI::httpClient()->get($url, $accept, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() && $curlResult->getReturnCode() == '406') { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); $html_fetched = true; } else { $html_fetched = false; @@ -655,10 +656,10 @@ class GServer $serverdata = $data['server']; $systemactor = $data['actor']; if (!$html_fetched && !in_array($serverdata['detection-method'], [self::DETECT_SYSTEM_ACTOR, self::DETECT_AP_COLLECTION])) { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); } } elseif (!$html_fetched && (strlen($curlResult->getBodyString()) < 1000)) { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); } if ($serverdata['detection-method'] != self::DETECT_SYSTEM_ACTOR) { @@ -867,7 +868,7 @@ class GServer { Logger::info('Discover relay data', ['server' => $server_url]); - $curlResult = DI::httpClient()->get($server_url . '/.well-known/x-social-relay', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($server_url . '/.well-known/x-social-relay', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return; } @@ -962,7 +963,7 @@ class GServer */ private static function fetchStatistics(string $url, array $serverdata): array { - $curlResult = DI::httpClient()->get($url . '/statistics.json', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/statistics.json', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return $serverdata; } @@ -1109,7 +1110,7 @@ class GServer */ private static function parseNodeinfo1(string $nodeinfo_url): array { - $curlResult = DI::httpClient()->get($nodeinfo_url, HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($nodeinfo_url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return []; } @@ -1209,7 +1210,7 @@ class GServer */ private static function parseNodeinfo2(string $nodeinfo_url): array { - $curlResult = DI::httpClient()->get($nodeinfo_url, HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($nodeinfo_url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return []; } @@ -1429,7 +1430,7 @@ class GServer */ private static function fetchSiteinfo(string $url, array $serverdata): array { - $curlResult = DI::httpClient()->get($url . '/siteinfo.json', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/siteinfo.json', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return $serverdata; } @@ -1586,7 +1587,7 @@ class GServer private static function getNomadName(string $url): string { $name = 'nomad'; - $curlResult = DI::httpClient()->get($url . '/manifest', 'application/manifest+json'); + $curlResult = DI::httpClient()->get($url . '/manifest', 'application/manifest+json', [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) { return $name; } @@ -1607,7 +1608,7 @@ class GServer */ private static function getNomadVersion(string $url): string { - $curlResult = DI::httpClient()->get($url . '/api/z/1.0/version', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/z/1.0/version', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) { return ''; } @@ -1629,7 +1630,7 @@ class GServer private static function validHostMeta(string $url): bool { $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpClient()->get($url . Probe::HOST_META, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->get($url . Probe::HOST_META, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return false; } @@ -1728,7 +1729,7 @@ class GServer { $serverdata['poco'] = ''; - $curlResult = DI::httpClient()->get($url . '/poco', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/poco', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return $serverdata; } @@ -1758,7 +1759,7 @@ class GServer */ public static function checkMastodonDirectory(string $url, array $serverdata): array { - $curlResult = DI::httpClient()->get($url . '/api/v1/directory?limit=1', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/v1/directory?limit=1', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { return $serverdata; } @@ -1785,7 +1786,7 @@ class GServer */ private static function detectPeertube(string $url, array $serverdata): array { - $curlResult = DI::httpClient()->get($url . '/api/v1/config', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/v1/config', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) { return $serverdata; } @@ -1833,7 +1834,7 @@ class GServer */ private static function detectNextcloud(string $url, array $serverdata, bool $validHostMeta): array { - $curlResult = DI::httpClient()->get($url . '/status.php', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/status.php', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) { return $serverdata; } @@ -1869,7 +1870,7 @@ class GServer */ private static function fetchWeeklyUsage(string $url, array $serverdata): array { - $curlResult = DI::httpClient()->get($url . '/api/v1/instance/activity', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/v1/instance/activity', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) { return $serverdata; } @@ -1909,7 +1910,7 @@ class GServer */ private static function detectMastodonAlikes(string $url, array $serverdata): array { - $curlResult = DI::httpClient()->get($url . '/api/v1/instance', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/v1/instance', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) { return $serverdata; } @@ -1981,7 +1982,7 @@ class GServer */ private static function detectHubzilla(string $url, array $serverdata): array { - $curlResult = DI::httpClient()->get($url . '/api/statusnet/config.json', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/statusnet/config.json', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) { return $serverdata; } @@ -2078,7 +2079,7 @@ class GServer private static function detectGNUSocial(string $url, array $serverdata): array { // Test for GNU Social - $curlResult = DI::httpClient()->get($url . '/api/gnusocial/version.json', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/gnusocial/version.json', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if ($curlResult->isSuccess() && ($curlResult->getBodyString() != '{"error":"not implemented"}') && ($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) { $serverdata['platform'] = 'gnusocial'; @@ -2096,7 +2097,7 @@ class GServer } // Test for Statusnet - $curlResult = DI::httpClient()->get($url . '/api/statusnet/version.json', HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url . '/api/statusnet/version.json', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if ($curlResult->isSuccess() && ($curlResult->getBodyString() != '{"error":"not implemented"}') && ($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) { @@ -2134,9 +2135,9 @@ class GServer { // There is a bug in some versions of Friendica that will return an ActivityStream actor when the content type "application/json" is requested. // Because of this me must not use ACCEPT_JSON here. - $curlResult = DI::httpClient()->get($url . '/friendica/json'); + $curlResult = DI::httpClient()->get($url . '/friendica/json', HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); if (!$curlResult->isSuccess()) { - $curlResult = DI::httpClient()->get($url . '/friendika/json'); + $curlResult = DI::httpClient()->get($url . '/friendika/json', HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERINFO]); $friendika = true; $platform = 'Friendika'; } else { @@ -2447,7 +2448,7 @@ class GServer $protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus']; foreach ($protocols as $protocol) { $query = '{nodes(protocol:"' . $protocol . '"){host}}'; - $curlResult = DI::httpClient()->fetch('https://the-federation.info/graphql?query=' . urlencode($query), HttpClientAccept::JSON); + $curlResult = DI::httpClient()->fetch('https://the-federation.info/graphql?query=' . urlencode($query), HttpClientAccept::JSON, 0, '', HttpClientRequest::SERVERDISCOVER); if (!empty($curlResult)) { $data = json_decode($curlResult, true); if (!empty($data['data']['nodes'])) { @@ -2464,7 +2465,7 @@ class GServer if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; - $curlResult = DI::httpClient()->get($api, HttpClientAccept::JSON, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]]]); + $curlResult = DI::httpClient()->get($api, HttpClientAccept::JSON, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken], HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]]); if ($curlResult->isSuccess()) { $servers = json_decode($curlResult->getBodyString(), true); diff --git a/src/Model/Item.php b/src/Model/Item.php index 084df8d229..1b4d5d11a3 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -39,6 +39,7 @@ use Friendica\DI; use Friendica\Model\Post\Category; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\ServiceUnavailableException; use Friendica\Protocol\Activity; @@ -4141,7 +4142,7 @@ class Item } try { - $curlResult = DI::httpClient()->head($uri, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON_AS]); + $curlResult = DI::httpClient()->head($uri, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON_AS, HttpClientOptions::REQUEST => HttpClientRequest::ACTIVITYPUB]); if (HTTPSignature::isValidContentType($curlResult->getContentType(), $uri)) { $fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri, [], '', $completion, $uid); } diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index 5d9d512f8f..802ad668cf 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -36,6 +36,7 @@ use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Protocol\ActivityPub; use Friendica\Util\Images; use Friendica\Util\Network; @@ -188,7 +189,7 @@ class Media // Fetch the mimetype or size if missing. if (Network::isValidHttpUrl($media['url']) && (empty($media['mimetype']) || empty($media['size']))) { $timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout]); + $curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]); // Workaround for systems that can't handle a HEAD request if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) { diff --git a/src/Model/User.php b/src/Model/User.php index 2ba7f6b90c..3728458258 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -38,6 +38,8 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Module; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\HTTPException; use Friendica\Object\Image; use Friendica\Protocol\Delivery; @@ -1400,7 +1402,7 @@ class User $photo_failure = false; $filename = basename($photo); - $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE); + $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]); if ($curlResult->isSuccess()) { Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]); $img_str = $curlResult->getBodyString(); diff --git a/src/Module/Contact/MatchInterests.php b/src/Module/Contact/MatchInterests.php index ac35244049..1b783e4b00 100644 --- a/src/Module/Contact/MatchInterests.php +++ b/src/Module/Contact/MatchInterests.php @@ -37,6 +37,7 @@ use Friendica\Module\Contact as ModuleContact; use Friendica\Module\Response; use Friendica\Navigation\SystemMessages; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; @@ -122,10 +123,10 @@ class MatchInterests extends BaseModule continue; } - $result = $this->httpClient->post($server . '/search/user/tags', $searchParameters); + $result = $this->httpClient->post($server . '/search/user/tags', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER); if (!$result->isSuccess()) { // try legacy endpoint - $result = $this->httpClient->post($server . '/msearch', $searchParameters); + $result = $this->httpClient->post($server . '/msearch', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER); if (!$result->isSuccess()) { $this->logger->notice('Search-Endpoint not available for server.', ['server' => $server]); continue; diff --git a/src/Module/Debug/Feed.php b/src/Module/Debug/Feed.php index 954a86aba4..7a4feabdf5 100644 --- a/src/Module/Debug/Feed.php +++ b/src/Module/Debug/Feed.php @@ -30,6 +30,7 @@ use Friendica\Model; use Friendica\Module\Response; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Protocol; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; @@ -62,7 +63,7 @@ class Feed extends BaseModule $contact = Model\Contact::getByURLForUser($url, DI::userSession()->getLocalUserId(), null); - $xml = $this->httpClient->fetch($contact['poll'], HttpClientAccept::FEED_XML); + $xml = $this->httpClient->fetch($contact['poll'], HttpClientAccept::FEED_XML, 0, '', HttpClientRequest::FEEDFETCHER); $import_result = Protocol\Feed::import($xml); diff --git a/src/Module/OStatus/PubSubHubBub.php b/src/Module/OStatus/PubSubHubBub.php index e4cc5d7209..02045ae8ac 100644 --- a/src/Module/OStatus/PubSubHubBub.php +++ b/src/Module/OStatus/PubSubHubBub.php @@ -28,6 +28,8 @@ use Friendica\Database\Database; use Friendica\Model\PushSubscriber; use Friendica\Module\Response; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\HTTPException; use Friendica\Util\Profiler; use Friendica\Util\Strings; @@ -153,7 +155,7 @@ class PubSubHubBub extends \Friendica\BaseModule $hub_callback = rtrim($hub_callback, ' ?&#'); $separator = parse_url($hub_callback, PHP_URL_QUERY) === null ? '?' : '&'; - $fetchResult = $this->httpClient->fetchFull($hub_callback . $separator . $params); + $fetchResult = $this->httpClient->fetchFull($hub_callback . $separator . $params, HttpClientAccept::DEFAULT, 0, '', HttpClientRequest::PUBSUB); $body = $fetchResult->getBodyString(); $returnCode = $fetchResult->getReturnCode(); diff --git a/src/Module/OStatus/Subscribe.php b/src/Module/OStatus/Subscribe.php index cee49d5b94..f9abf41b74 100644 --- a/src/Module/OStatus/Subscribe.php +++ b/src/Module/OStatus/Subscribe.php @@ -32,6 +32,8 @@ use Friendica\Module\Response; use Friendica\Navigation\SystemMessages; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Protocol\ActivityPub; use Friendica\Util\Profiler; use Psr\Log\LoggerInterface; @@ -89,7 +91,7 @@ class Subscribe extends \Friendica\BaseModule $api = $contact['baseurl'] . '/api/'; // Fetching friends - $curlResult = $this->httpClient->get($api . 'statuses/friends.json?screen_name=' . $contact['nick'], HttpClientAccept::JSON); + $curlResult = $this->httpClient->get($api . 'statuses/friends.json?screen_name=' . $contact['nick'], HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::OSTATUS]); if (!$curlResult->isSuccess()) { $this->pConfig->delete($uid, 'ostatus', 'legacy_contact'); diff --git a/src/Module/Photo.php b/src/Module/Photo.php index 2386d51548..7b56732301 100644 --- a/src/Module/Photo.php +++ b/src/Module/Photo.php @@ -369,7 +369,7 @@ class Photo extends BaseApi $update = in_array($contact['network'], Protocol::FEDERATED) && !$contact['failed'] && ((time() - strtotime($contact['updated']) > 86400)); if ($update) { - $curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::IMAGE, HttpClientOptions::REQUEST => HttpClientRequest::MEDIAPROXY]); + $curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::IMAGE, HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]); $update = !$curlResult->isSuccess() && ($curlResult->getReturnCode() == 404); Logger::debug('Got return code for avatar', ['return code' => $curlResult->getReturnCode(), 'cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); } diff --git a/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php b/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php index fdbc2b18a1..56f3b67725 100644 --- a/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php +++ b/src/Network/HTTPClient/Capability/ICanSendHttpRequests.php @@ -39,10 +39,11 @@ interface ICanSendHttpRequests * @param string $accept_content supply Accept: header with 'accept_content' as the value * @param int $timeout Timeout in seconds, default system config value or 60 seconds * @param string $cookiejar Path to cookie jar file + * @param string $request Request Type * * @return string The fetched content */ - public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): string; + public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): string; /** * Fetches the whole response of an URL. @@ -54,10 +55,11 @@ interface ICanSendHttpRequests * @param string $accept_content supply Accept: header with 'accept_content' as the value * @param int $timeout Timeout in seconds, default system config value or 60 seconds * @param string $cookiejar Path to cookie jar file + * @param string $request Request Type * * @return ICanHandleHttpResponses With all relevant information, 'body' contains the actual fetched content. */ - public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): ICanHandleHttpResponses; + public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): ICanHandleHttpResponses; /** * Send a GET to a URL. diff --git a/src/Network/HTTPClient/Client/HttpClient.php b/src/Network/HTTPClient/Client/HttpClient.php index a8fb4e13c4..934fe56d93 100644 --- a/src/Network/HTTPClient/Client/HttpClient.php +++ b/src/Network/HTTPClient/Client/HttpClient.php @@ -267,7 +267,7 @@ class HttpClient implements ICanSendHttpRequests $url = trim($url, "'"); - $this->resolver->setUserAgent($this->getUserAgent(HttpClientRequest::RESOLVER)); + $this->resolver->setUserAgent($this->getUserAgent(HttpClientRequest::URLRESOLVER)); $urlResult = $this->resolver->resolveURL($url); if ($urlResult->didErrorOccur()) { @@ -280,9 +280,9 @@ class HttpClient implements ICanSendHttpRequests /** * {@inheritDoc} */ - public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): string + public function fetch(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): string { - $ret = $this->fetchFull($url, $accept_content, $timeout, $cookiejar); + $ret = $this->fetchFull($url, $accept_content, $timeout, $cookiejar, $request); return $ret->getBodyString(); } @@ -290,14 +290,15 @@ class HttpClient implements ICanSendHttpRequests /** * {@inheritDoc} */ - public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = ''): ICanHandleHttpResponses + public function fetchFull(string $url, string $accept_content = HttpClientAccept::DEFAULT, int $timeout = 0, string $cookiejar = '', string $request = ''): ICanHandleHttpResponses { return $this->get( $url, $accept_content, [ HttpClientOptions::TIMEOUT => $timeout, - HttpClientOptions::COOKIEJAR => $cookiejar + HttpClientOptions::COOKIEJAR => $cookiejar, + HttpClientOptions::REQUEST => $request, ] ); } diff --git a/src/Network/HTTPClient/Client/HttpClientRequest.php b/src/Network/HTTPClient/Client/HttpClientRequest.php index 19967a660f..34d513df9f 100644 --- a/src/Network/HTTPClient/Client/HttpClientRequest.php +++ b/src/Network/HTTPClient/Client/HttpClientRequest.php @@ -26,14 +26,23 @@ namespace Friendica\Network\HTTPClient\Client; */ class HttpClientRequest { - public const ACTIVITYPUB = 'ActivityPub/1'; - public const CONTENTTYPE = 'ContentTypeChecker/1'; - public const DFRN = 'DFRN/1'; - public const DIASPORA = 'Diaspora/1'; - public const MAGICAUTH = 'MagicAuth/1'; - public const MEDIAPROXY = 'MediaProxy/1'; - public const SALMON = 'Salmon/1'; - public const PUBSUB = 'PubSub/1'; - public const RESOLVER = 'URLResolver/1'; - public const VERIFIER = 'URLVerifier/1'; + public const ACTIVITYPUB = 'ActivityPub/1'; + public const CONTACTINFO = 'ContactInfo/1'; + public const CONTACTDISCOVER = 'ContactDiscover/1'; + public const CONTACTVERIFIER = 'ContactVerifier/1'; + public const CONTENTTYPE = 'ContentTypeChecker/1'; + public const DFRN = 'DFRN/1'; + public const DIASPORA = 'Diaspora/1'; + public const FEEDFETCHER = 'FeedFetcher/1'; + public const MAGICAUTH = 'MagicAuth/1'; + public const MEDIAPROXY = 'MediaProxy/1'; + public const MEDIAVERIFIER = 'MediaVerifier/1'; + public const OSTATUS = 'OStatus/1'; + public const SALMON = 'Salmon/1'; + public const SERVERINFO = 'ServerInfo/1'; + public const SERVERDISCOVER = 'ServerDiscover/1'; + public const SITEINFO = 'SiteInfo/1'; + public const PUBSUB = 'PubSub/1'; + public const URLRESOLVER = 'URLResolver/1'; + public const URLVERIFIER = 'URLVerifier/1'; } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 736942ed22..e577ab293b 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -35,6 +35,7 @@ use Friendica\Model\Profile; use Friendica\Model\User; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\Diaspora; @@ -225,7 +226,7 @@ class Probe Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url]); $xrd = null; - $curlResult = DI::httpClient()->get($ssl_url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->get($ssl_url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); $ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0); if ($curlResult->isSuccess()) { $xml = $curlResult->getBodyString(); @@ -242,7 +243,7 @@ class Probe } if (!is_object($xrd) && !empty($url)) { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); $connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0); if ($curlResult->isTimeout()) { Logger::info('Probing timeout', ['url' => $url]); @@ -452,7 +453,7 @@ class Probe */ private static function getHideStatus(string $url): bool { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000]); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if (!$curlResult->isSuccess()) { return false; } @@ -864,7 +865,7 @@ class Probe public static function pollZot(string $url, array $data): array { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if ($curlResult->isTimeout()) { return $data; } @@ -963,7 +964,7 @@ class Probe $curlResult = DI::httpClient()->get( $url, $type, - [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout', 20)] + [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout', 20), HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO] ); } catch (\Throwable $e) { Logger::notice($e->getMessage(), ['url' => $url, 'type' => $type, 'class' => get_class($e)]); @@ -1038,7 +1039,7 @@ class Probe */ private static function pollNoscrape(string $noscrape_url, array $data): array { - $curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if ($curlResult->isTimeout()) { self::$isTimeout = true; return $data; @@ -1301,7 +1302,7 @@ class Probe */ private static function pollHcard(string $hcard_url, array $data, bool $dfrn = false): array { - $curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML); + $curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if ($curlResult->isTimeout()) { self::$isTimeout = true; return []; @@ -1577,7 +1578,7 @@ class Probe $pubkey = substr($pubkey, 5); } } elseif (Strings::normaliseLink($pubkey) == 'http://') { - $curlResult = DI::httpClient()->get($pubkey, HttpClientAccept::MAGIC_KEY); + $curlResult = DI::httpClient()->get($pubkey, HttpClientAccept::MAGIC_KEY, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if ($curlResult->isTimeout()) { self::$isTimeout = true; return $short ? false : []; @@ -1610,7 +1611,7 @@ class Probe } // Fetch all additional data from the feed - $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML); + $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if ($curlResult->isTimeout()) { self::$isTimeout = true; return []; @@ -1662,7 +1663,7 @@ class Probe */ private static function pumpioProfileData(string $profile_link, string $baseurl): array { - $curlResult = DI::httpClient()->get($profile_link, HttpClientAccept::HTML); + $curlResult = DI::httpClient()->get($profile_link, HttpClientAccept::HTML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) { return []; } @@ -1879,7 +1880,7 @@ class Probe private static function feed(string $url, bool $probe = true): array { try { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); } catch(\Throwable $e) { DI::logger()->info('Error requesting feed URL', ['url' => $url, 'exception' => $e]); return []; @@ -2113,7 +2114,7 @@ class Probe return ''; } - $curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if ($curlResult->isSuccess() && !empty($curlResult->getBodyString())) { $noscrape = json_decode($curlResult->getBodyString(), true); @@ -2189,7 +2190,7 @@ class Probe private static function updateFromFeed(array $data): string { // Search for the newest entry in the feed - $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::ATOM_XML); + $curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]); if (!$curlResult->isSuccess() || !$curlResult->getBodyString()) { return ''; } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index c74c52e0a6..526ef11a90 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1082,7 +1082,7 @@ class Diaspora Logger::info('Fetch post from ' . $source_url); - $envelope = DI::httpClient()->fetch($source_url, HttpClientAccept::MAGIC); + $envelope = DI::httpClient()->fetch($source_url, HttpClientAccept::MAGIC, 0, '', HttpClientRequest::DIASPORA); if ($envelope) { Logger::info('Envelope was fetched.'); $x = self::verifyMagicEnvelope($envelope); diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index fa93b0e827..0e4fd5cbc4 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -41,6 +41,8 @@ use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; use Friendica\Util\Images; @@ -734,7 +736,7 @@ class OStatus private static function fetchRelated(string $related, string $related_uri, array $importer) { $stored = false; - $curlResult = DI::httpClient()->get($related, HttpClientAccept::ATOM_XML); + $curlResult = DI::httpClient()->get($related, HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::OSTATUS]); if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) { return; @@ -766,7 +768,7 @@ class OStatus } } if ($atom_file != '') { - $curlResult = DI::httpClient()->get($atom_file, HttpClientAccept::ATOM_XML); + $curlResult = DI::httpClient()->get($atom_file, HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::OSTATUS]); if ($curlResult->isSuccess()) { Logger::info('Fetched XML for URI ' . $related_uri); @@ -778,7 +780,7 @@ class OStatus // Workaround for older GNU Social servers if (($xml == '') && strstr($related, '/notice/')) { - $curlResult = DI::httpClient()->get(str_replace('/notice/', '/api/statuses/show/', $related) . '.atom', HttpClientAccept::ATOM_XML); + $curlResult = DI::httpClient()->get(str_replace('/notice/', '/api/statuses/show/', $related) . '.atom', HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::OSTATUS]); if ($curlResult->isSuccess()) { Logger::info('GNU Social workaround to fetch XML for URI ' . $related_uri); @@ -789,7 +791,7 @@ class OStatus // Even more worse workaround for GNU Social ;-) if ($xml == '') { $related_guess = self::convertHref($related_uri); - $curlResult = DI::httpClient()->get(str_replace('/notice/', '/api/statuses/show/', $related_guess) . '.atom', HttpClientAccept::ATOM_XML); + $curlResult = DI::httpClient()->get(str_replace('/notice/', '/api/statuses/show/', $related_guess) . '.atom', HttpClientAccept::ATOM_XML, [HttpClientOptions::REQUEST => HttpClientRequest::OSTATUS]); if ($curlResult->isSuccess()) { Logger::info('GNU Social workaround 2 to fetch XML for URI ' . $related_uri); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 7f311a4084..d4331570a3 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -76,7 +76,7 @@ class Salmon $ret[$x] = substr($ret[$x], 5); } } elseif (Strings::normaliseLink($ret[$x]) == 'http://') { - $ret[$x] = DI::httpClient()->fetch($ret[$x], HttpClientAccept::MAGIC_KEY); + $ret[$x] = DI::httpClient()->fetch($ret[$x], HttpClientAccept::MAGIC_KEY, 0, '', HttpClientRequest::SALMON); Logger::debug('Fetched public key', ['url' => $ret[$x]]); } } diff --git a/src/Security/ExAuth.php b/src/Security/ExAuth.php index eda2f398e6..728d7482ac 100644 --- a/src/Security/ExAuth.php +++ b/src/Security/ExAuth.php @@ -58,6 +58,8 @@ use Friendica\Database\Database; use Friendica\DI; use Friendica\Model\User; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Network\HTTPException; use Friendica\Util\PidFile; @@ -240,7 +242,7 @@ class ExAuth $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; - $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]); if (!$curlResult->isSuccess()) { return false; diff --git a/src/Util/Images.php b/src/Util/Images.php index dac6f15aec..a694944b04 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -26,6 +26,7 @@ use Friendica\Core\Logger; use Friendica\DI; use Friendica\Model\Photo; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Object\Image; /** @@ -356,7 +357,7 @@ class Images if (empty($img_str)) { try { - $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4); + $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4, '', HttpClientRequest::MEDIAVERIFIER); } catch (\Exception $exception) { Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]); return []; diff --git a/src/Util/Network.php b/src/Util/Network.php index d6c91d317d..1c2b3c8e5c 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -80,7 +80,7 @@ class Network if (in_array(parse_url($url, PHP_URL_SCHEME), ['https', 'http'])) { $options = [HttpClientOptions::VERIFY => true, HttpClientOptions::TIMEOUT => $xrd_timeout, - HttpClientOptions::REQUEST => HttpClientRequest::VERIFIER]; + HttpClientOptions::REQUEST => HttpClientRequest::URLVERIFIER]; try { $curlResult = DI::httpClient()->head($url, $options); } catch (\Exception $e) { diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 5687aea3c5..d4b54b9629 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -234,7 +234,7 @@ class ParseUrl } try { - $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000]); + $curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]); } catch (\Throwable $th) { Logger::info('Exception when fetching', ['url' => $url, 'code' => $th->getCode(), 'message' => $th->getMessage()]); return $siteinfo; diff --git a/src/Worker/CheckRelMeProfileLink.php b/src/Worker/CheckRelMeProfileLink.php index a6bfc9b4c4..3dc0ba497e 100644 --- a/src/Worker/CheckRelMeProfileLink.php +++ b/src/Worker/CheckRelMeProfileLink.php @@ -29,6 +29,7 @@ use Friendica\Model\Profile; use Friendica\Model\User; use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use GuzzleHttp\Psr7\Uri; /* This class is used to verify the homepage link of a user profile. @@ -64,7 +65,7 @@ class CheckRelMeProfileLink } $xrd_timeout = DI::config()->get('system', 'xrd_timeout'); - $curlResult = DI::httpClient()->get($owner['homepage'], HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout]); + $curlResult = DI::httpClient()->get($owner['homepage'], HttpClientAccept::HTML, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::REQUEST => HttpClientRequest::CONTACTVERIFIER]); if (!$curlResult->isSuccess()) { Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]); return; diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index 746b9084a3..34ac2d0611 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -28,6 +28,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; /** * Sends updated profile data to the directory @@ -55,7 +56,7 @@ class Directory Logger::info('Updating directory: ' . $arr['url']); if (strlen($arr['url'])) { - DI::httpClient()->fetch($dir . '?url=' . bin2hex($arr['url']), HttpClientAccept::HTML); + DI::httpClient()->fetch($dir . '?url=' . bin2hex($arr['url']), HttpClientAccept::HTML, 0, '', HttpClientRequest::CONTACTDISCOVER); } return; diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 0991e4157a..838f30a4e4 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -165,7 +165,7 @@ class OnePoll } $cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-'); - $curlResult = DI::httpClient()->get($contact['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::COOKIEJAR => $cookiejar]); + $curlResult = DI::httpClient()->get($contact['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::COOKIEJAR => $cookiejar, HttpClientOptions::REQUEST => HttpClientRequest::FEEDFETCHER]); unlink($cookiejar); if ($curlResult->isTimeout()) { diff --git a/src/Worker/PullDirectory.php b/src/Worker/PullDirectory.php index 8acad8bbd7..37848b4967 100644 --- a/src/Worker/PullDirectory.php +++ b/src/Worker/PullDirectory.php @@ -26,6 +26,7 @@ use Friendica\Core\Search; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; class PullDirectory { @@ -49,7 +50,7 @@ class PullDirectory Logger::info('Synchronization started.', ['now' => $now, 'directory' => $directory]); - $result = DI::httpClient()->fetch($directory . '/sync/pull/since/' . $now, HttpClientAccept::JSON); + $result = DI::httpClient()->fetch($directory . '/sync/pull/since/' . $now, HttpClientAccept::JSON, 0, '', HttpClientRequest::CONTACTDISCOVER); if (empty($result)) { Logger::info('Directory server return empty result.', ['directory' => $directory]); return; diff --git a/src/Worker/SearchDirectory.php b/src/Worker/SearchDirectory.php index 7e7234efa9..34d3299b6b 100644 --- a/src/Worker/SearchDirectory.php +++ b/src/Worker/SearchDirectory.php @@ -27,6 +27,7 @@ use Friendica\Core\Search; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; class SearchDirectory { @@ -47,7 +48,7 @@ class SearchDirectory } } - $x = DI::httpClient()->fetch(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search), HttpClientAccept::JSON); + $x = DI::httpClient()->fetch(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search), HttpClientAccept::JSON, 0, '', HttpClientRequest::CONTACTDISCOVER); $j = json_decode($x); if (!empty($j->results)) { diff --git a/src/Worker/UpdateServerDirectory.php b/src/Worker/UpdateServerDirectory.php index 5990213d32..e41fe11861 100644 --- a/src/Worker/UpdateServerDirectory.php +++ b/src/Worker/UpdateServerDirectory.php @@ -26,6 +26,7 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\GServer; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; class UpdateServerDirectory { @@ -49,7 +50,7 @@ class UpdateServerDirectory private static function discoverPoCo(array $gserver) { - $result = DI::httpClient()->fetch($gserver['poco'] . '?fields=urls', HttpClientAccept::JSON); + $result = DI::httpClient()->fetch($gserver['poco'] . '?fields=urls', HttpClientAccept::JSON, 0, '', HttpClientRequest::SERVERDISCOVER); if (empty($result)) { Logger::info('Empty result', ['url' => $gserver['url']]); return; @@ -82,7 +83,7 @@ class UpdateServerDirectory private static function discoverMastodonDirectory(array $gserver) { - $result = DI::httpClient()->fetch($gserver['url'] . '/api/v1/directory?order=new&local=true&limit=200&offset=0', HttpClientAccept::JSON); + $result = DI::httpClient()->fetch($gserver['url'] . '/api/v1/directory?order=new&local=true&limit=200&offset=0', HttpClientAccept::JSON, 0, '', HttpClientRequest::SERVERDISCOVER); if (empty($result)) { Logger::info('Empty result', ['url' => $gserver['url']]); return; diff --git a/src/Worker/UpdateServerPeers.php b/src/Worker/UpdateServerPeers.php index dd08f5cb40..74240179ba 100644 --- a/src/Worker/UpdateServerPeers.php +++ b/src/Worker/UpdateServerPeers.php @@ -27,6 +27,8 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\GServer; use Friendica\Network\HTTPClient\Client\HttpClientAccept; +use Friendica\Network\HTTPClient\Client\HttpClientOptions; +use Friendica\Network\HTTPClient\Client\HttpClientRequest; use Friendica\Util\Network; use Friendica\Util\Strings; @@ -44,7 +46,7 @@ class UpdateServerPeers return; } - $ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON); + $ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON, [HttpClientOptions::REQUEST => HttpClientRequest::SERVERDISCOVER]); if (!$ret->isSuccess() || empty($ret->getBodyString())) { Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]); return;