Request type set for all HTTP requests

This commit is contained in:
Michael 2024-05-12 17:53:21 +00:00
parent d788cb82cc
commit 5751e024c0
30 changed files with 129 additions and 90 deletions

View file

@ -32,6 +32,7 @@ use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
@ -86,7 +87,7 @@ class OEmbed
if (!in_array($ext, $noexts)) { if (!in_array($ext, $noexts)) {
// try oembed autodiscovery // 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)) { if (!empty($html_text)) {
$dom = new DOMDocument(); $dom = new DOMDocument();
if (@$dom->loadHTML($html_text)) { if (@$dom->loadHTML($html_text)) {
@ -100,7 +101,7 @@ class OEmbed
// but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯ // but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
$href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'], $href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'],
['https://www.youtube.com/', 'https://player.vimeo.com/'], $href); ['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()) { if ($result->isSuccess()) {
$json_string = $result->getBodyString(); $json_string = $result->getBodyString();
break; break;

View file

@ -974,7 +974,7 @@ class BBCode
$text = '[url=' . $match[2] . ']' . $match[2] . '[/url]'; $text = '[url=' . $match[2] . ']' . $match[2] . '[/url]';
// if its not a picture then look if its a page that contains a picture link // 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)) { if (empty($body)) {
DI::cache()->set($cache_key, $text); DI::cache()->set($cache_key, $text);
return $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 // 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)) { if (empty($body)) {
DI::cache()->set($cache_key, $text); DI::cache()->set($cache_key, $text);
return $text; return $text;

View file

@ -24,6 +24,8 @@ namespace Friendica\Core;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ContactResult;
use Friendica\Object\Search\ResultList; use Friendica\Object\Search\ResultList;
@ -125,7 +127,7 @@ class Search
$searchUrl .= '&page=' . $page; $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); $results = json_decode($resultJson, true);
@ -232,7 +234,7 @@ class Search
$return = Contact::searchByName($search, $mode, true); $return = Contact::searchByName($search, $mode, true);
} else { } else {
$p = $page > 1 ? 'p=' . $page : ''; $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()) { if ($curlResult->isSuccess()) {
$searchResult = json_decode($curlResult->getBodyString(), true); $searchResult = json_decode($curlResult->getBodyString(), true);
if (!empty($searchResult['profiles'])) { if (!empty($searchResult['profiles'])) {

View file

@ -34,6 +34,7 @@ use Friendica\Module\Register;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses; use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\Relay; use Friendica\Protocol\Relay;
@ -611,7 +612,7 @@ class GServer
$in_webroot = empty(parse_url($url, PHP_URL_PATH)); $in_webroot = empty(parse_url($url, PHP_URL_PATH));
// When a nodeinfo is present, we don't need to dig further // 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()) { if ($curlResult->isTimeout()) {
self::setFailureByUrl($url); self::setFailureByUrl($url);
return false; return false;
@ -622,7 +623,7 @@ class GServer
} else { } else {
$serverdata = self::parseNodeinfo210($curlResult); $serverdata = self::parseNodeinfo210($curlResult);
if (empty($serverdata)) { 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); $serverdata = self::fetchNodeinfo($url, $curlResult);
} }
} }
@ -640,9 +641,9 @@ class GServer
if ($in_webroot) { if ($in_webroot) {
// Fetch the landing page, possibly it reveals some data // Fetch the landing page, possibly it reveals some data
$accept = 'application/activity+json,application/ld+json,application/json,*/*;q=0.9'; $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') { 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; $html_fetched = true;
} else { } else {
$html_fetched = false; $html_fetched = false;
@ -655,10 +656,10 @@ class GServer
$serverdata = $data['server']; $serverdata = $data['server'];
$systemactor = $data['actor']; $systemactor = $data['actor'];
if (!$html_fetched && !in_array($serverdata['detection-method'], [self::DETECT_SYSTEM_ACTOR, self::DETECT_AP_COLLECTION])) { 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)) { } 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) { if ($serverdata['detection-method'] != self::DETECT_SYSTEM_ACTOR) {
@ -867,7 +868,7 @@ class GServer
{ {
Logger::info('Discover relay data', ['server' => $server_url]); 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()) { if (!$curlResult->isSuccess()) {
return; return;
} }
@ -962,7 +963,7 @@ class GServer
*/ */
private static function fetchStatistics(string $url, array $serverdata): array 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()) { if (!$curlResult->isSuccess()) {
return $serverdata; return $serverdata;
} }
@ -1109,7 +1110,7 @@ class GServer
*/ */
private static function parseNodeinfo1(string $nodeinfo_url): array 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()) { if (!$curlResult->isSuccess()) {
return []; return [];
} }
@ -1209,7 +1210,7 @@ class GServer
*/ */
private static function parseNodeinfo2(string $nodeinfo_url): array 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()) { if (!$curlResult->isSuccess()) {
return []; return [];
} }
@ -1429,7 +1430,7 @@ class GServer
*/ */
private static function fetchSiteinfo(string $url, array $serverdata): array 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()) { if (!$curlResult->isSuccess()) {
return $serverdata; return $serverdata;
} }
@ -1586,7 +1587,7 @@ class GServer
private static function getNomadName(string $url): string private static function getNomadName(string $url): string
{ {
$name = 'nomad'; $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() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $name; return $name;
} }
@ -1607,7 +1608,7 @@ class GServer
*/ */
private static function getNomadVersion(string $url): string 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() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return ''; return '';
} }
@ -1629,7 +1630,7 @@ class GServer
private static function validHostMeta(string $url): bool private static function validHostMeta(string $url): bool
{ {
$xrd_timeout = DI::config()->get('system', 'xrd_timeout'); $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()) { if (!$curlResult->isSuccess()) {
return false; return false;
} }
@ -1728,7 +1729,7 @@ class GServer
{ {
$serverdata['poco'] = ''; $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()) { if (!$curlResult->isSuccess()) {
return $serverdata; return $serverdata;
} }
@ -1758,7 +1759,7 @@ class GServer
*/ */
public static function checkMastodonDirectory(string $url, array $serverdata): array 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()) { if (!$curlResult->isSuccess()) {
return $serverdata; return $serverdata;
} }
@ -1785,7 +1786,7 @@ class GServer
*/ */
private static function detectPeertube(string $url, array $serverdata): array 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() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata; return $serverdata;
} }
@ -1833,7 +1834,7 @@ class GServer
*/ */
private static function detectNextcloud(string $url, array $serverdata, bool $validHostMeta): array 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() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata; return $serverdata;
} }
@ -1869,7 +1870,7 @@ class GServer
*/ */
private static function fetchWeeklyUsage(string $url, array $serverdata): array 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() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata; return $serverdata;
} }
@ -1909,7 +1910,7 @@ class GServer
*/ */
private static function detectMastodonAlikes(string $url, array $serverdata): array 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() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata; return $serverdata;
} }
@ -1981,7 +1982,7 @@ class GServer
*/ */
private static function detectHubzilla(string $url, array $serverdata): array 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() == '')) { if (!$curlResult->isSuccess() || ($curlResult->getBodyString() == '')) {
return $serverdata; return $serverdata;
} }
@ -2078,7 +2079,7 @@ class GServer
private static function detectGNUSocial(string $url, array $serverdata): array private static function detectGNUSocial(string $url, array $serverdata): array
{ {
// Test for GNU Social // 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"}') && if ($curlResult->isSuccess() && ($curlResult->getBodyString() != '{"error":"not implemented"}') &&
($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) { ($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) {
$serverdata['platform'] = 'gnusocial'; $serverdata['platform'] = 'gnusocial';
@ -2096,7 +2097,7 @@ class GServer
} }
// Test for Statusnet // 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"}') && if ($curlResult->isSuccess() && ($curlResult->getBodyString() != '{"error":"not implemented"}') &&
($curlResult->getBodyString() != '') && (strlen($curlResult->getBodyString()) < 30)) { ($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. // 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. // 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()) { 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; $friendika = true;
$platform = 'Friendika'; $platform = 'Friendika';
} else { } else {
@ -2447,7 +2448,7 @@ class GServer
$protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus']; $protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus'];
foreach ($protocols as $protocol) { foreach ($protocols as $protocol) {
$query = '{nodes(protocol:"' . $protocol . '"){host}}'; $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)) { if (!empty($curlResult)) {
$data = json_decode($curlResult, true); $data = json_decode($curlResult, true);
if (!empty($data['data']['nodes'])) { if (!empty($data['data']['nodes'])) {
@ -2464,7 +2465,7 @@ class GServer
if (!empty($accesstoken)) { if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0'; $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()) { if ($curlResult->isSuccess()) {
$servers = json_decode($curlResult->getBodyString(), true); $servers = json_decode($curlResult->getBodyString(), true);

View file

@ -39,6 +39,7 @@ use Friendica\DI;
use Friendica\Model\Post\Category; use Friendica\Model\Post\Category;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\ServiceUnavailableException; use Friendica\Network\HTTPException\ServiceUnavailableException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -4141,7 +4142,7 @@ class Item
} }
try { 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)) { if (HTTPSignature::isValidContentType($curlResult->getContentType(), $uri)) {
$fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri, [], '', $completion, $uid); $fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri, [], '', $completion, $uid);
} }

View file

@ -36,6 +36,7 @@ use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Network; use Friendica\Util\Network;
@ -188,7 +189,7 @@ class Media
// Fetch the mimetype or size if missing. // Fetch the mimetype or size if missing.
if (Network::isValidHttpUrl($media['url']) && (empty($media['mimetype']) || empty($media['size']))) { if (Network::isValidHttpUrl($media['url']) && (empty($media['mimetype']) || empty($media['size']))) {
$timeout = DI::config()->get('system', 'xrd_timeout'); $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 // Workaround for systems that can't handle a HEAD request
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) { if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {

View file

@ -38,6 +38,8 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Module; use Friendica\Module;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\Delivery; use Friendica\Protocol\Delivery;
@ -1400,7 +1402,7 @@ class User
$photo_failure = false; $photo_failure = false;
$filename = basename($photo); $filename = basename($photo);
$curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE); $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE, [HttpClientOptions::REQUEST => HttpClientRequest::CONTENTTYPE]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]); Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
$img_str = $curlResult->getBodyString(); $img_str = $curlResult->getBodyString();

View file

@ -37,6 +37,7 @@ use Friendica\Module\Contact as ModuleContact;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Navigation\SystemMessages; use Friendica\Navigation\SystemMessages;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\HTTPException\InternalServerErrorException; use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -122,10 +123,10 @@ class MatchInterests extends BaseModule
continue; 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()) { if (!$result->isSuccess()) {
// try legacy endpoint // try legacy endpoint
$result = $this->httpClient->post($server . '/msearch', $searchParameters); $result = $this->httpClient->post($server . '/msearch', $searchParameters, [], 0, HttpClientRequest::CONTACTDISCOVER);
if (!$result->isSuccess()) { if (!$result->isSuccess()) {
$this->logger->notice('Search-Endpoint not available for server.', ['server' => $server]); $this->logger->notice('Search-Endpoint not available for server.', ['server' => $server]);
continue; continue;

View file

@ -30,6 +30,7 @@ use Friendica\Model;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Protocol; use Friendica\Protocol;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -62,7 +63,7 @@ class Feed extends BaseModule
$contact = Model\Contact::getByURLForUser($url, DI::userSession()->getLocalUserId(), null); $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); $import_result = Protocol\Feed::import($xml);

View file

@ -28,6 +28,8 @@ use Friendica\Database\Database;
use Friendica\Model\PushSubscriber; use Friendica\Model\PushSubscriber;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -153,7 +155,7 @@ class PubSubHubBub extends \Friendica\BaseModule
$hub_callback = rtrim($hub_callback, ' ?&#'); $hub_callback = rtrim($hub_callback, ' ?&#');
$separator = parse_url($hub_callback, PHP_URL_QUERY) === null ? '?' : '&'; $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(); $body = $fetchResult->getBodyString();
$returnCode = $fetchResult->getReturnCode(); $returnCode = $fetchResult->getReturnCode();

View file

@ -32,6 +32,8 @@ use Friendica\Module\Response;
use Friendica\Navigation\SystemMessages; use Friendica\Navigation\SystemMessages;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -89,7 +91,7 @@ class Subscribe extends \Friendica\BaseModule
$api = $contact['baseurl'] . '/api/'; $api = $contact['baseurl'] . '/api/';
// Fetching friends // 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()) { if (!$curlResult->isSuccess()) {
$this->pConfig->delete($uid, 'ostatus', 'legacy_contact'); $this->pConfig->delete($uid, 'ostatus', 'legacy_contact');

View file

@ -369,7 +369,7 @@ class Photo extends BaseApi
$update = in_array($contact['network'], Protocol::FEDERATED) && !$contact['failed'] $update = in_array($contact['network'], Protocol::FEDERATED) && !$contact['failed']
&& ((time() - strtotime($contact['updated']) > 86400)); && ((time() - strtotime($contact['updated']) > 86400));
if ($update) { 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); $update = !$curlResult->isSuccess() && ($curlResult->getReturnCode() == 404);
Logger::debug('Got return code for avatar', ['return code' => $curlResult->getReturnCode(), 'cid' => $id, 'url' => $contact['url'], 'avatar' => $url]); Logger::debug('Got return code for avatar', ['return code' => $curlResult->getReturnCode(), 'cid' => $id, 'url' => $contact['url'], 'avatar' => $url]);
} }

View file

@ -39,10 +39,11 @@ interface ICanSendHttpRequests
* @param string $accept_content supply Accept: header with 'accept_content' as the value * @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 int $timeout Timeout in seconds, default system config value or 60 seconds
* @param string $cookiejar Path to cookie jar file * @param string $cookiejar Path to cookie jar file
* @param string $request Request Type
* *
* @return string The fetched content * @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. * 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 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 int $timeout Timeout in seconds, default system config value or 60 seconds
* @param string $cookiejar Path to cookie jar file * @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. * @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. * Send a GET to a URL.

View file

@ -267,7 +267,7 @@ class HttpClient implements ICanSendHttpRequests
$url = trim($url, "'"); $url = trim($url, "'");
$this->resolver->setUserAgent($this->getUserAgent(HttpClientRequest::RESOLVER)); $this->resolver->setUserAgent($this->getUserAgent(HttpClientRequest::URLRESOLVER));
$urlResult = $this->resolver->resolveURL($url); $urlResult = $this->resolver->resolveURL($url);
if ($urlResult->didErrorOccur()) { if ($urlResult->didErrorOccur()) {
@ -280,9 +280,9 @@ class HttpClient implements ICanSendHttpRequests
/** /**
* {@inheritDoc} * {@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(); return $ret->getBodyString();
} }
@ -290,14 +290,15 @@ class HttpClient implements ICanSendHttpRequests
/** /**
* {@inheritDoc} * {@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( return $this->get(
$url, $url,
$accept_content, $accept_content,
[ [
HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::TIMEOUT => $timeout,
HttpClientOptions::COOKIEJAR => $cookiejar HttpClientOptions::COOKIEJAR => $cookiejar,
HttpClientOptions::REQUEST => $request,
] ]
); );
} }

View file

@ -26,14 +26,23 @@ namespace Friendica\Network\HTTPClient\Client;
*/ */
class HttpClientRequest class HttpClientRequest
{ {
public const ACTIVITYPUB = 'ActivityPub/1'; public const ACTIVITYPUB = 'ActivityPub/1';
public const CONTENTTYPE = 'ContentTypeChecker/1'; public const CONTACTINFO = 'ContactInfo/1';
public const DFRN = 'DFRN/1'; public const CONTACTDISCOVER = 'ContactDiscover/1';
public const DIASPORA = 'Diaspora/1'; public const CONTACTVERIFIER = 'ContactVerifier/1';
public const MAGICAUTH = 'MagicAuth/1'; public const CONTENTTYPE = 'ContentTypeChecker/1';
public const MEDIAPROXY = 'MediaProxy/1'; public const DFRN = 'DFRN/1';
public const SALMON = 'Salmon/1'; public const DIASPORA = 'Diaspora/1';
public const PUBSUB = 'PubSub/1'; public const FEEDFETCHER = 'FeedFetcher/1';
public const RESOLVER = 'URLResolver/1'; public const MAGICAUTH = 'MagicAuth/1';
public const VERIFIER = 'URLVerifier/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';
} }

View file

@ -35,6 +35,7 @@ use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityNamespace;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
@ -225,7 +226,7 @@ class Probe
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url]); Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url]);
$xrd = null; $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); $ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$xml = $curlResult->getBodyString(); $xml = $curlResult->getBodyString();
@ -242,7 +243,7 @@ class Probe
} }
if (!is_object($xrd) && !empty($url)) { 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); $connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $url]); Logger::info('Probing timeout', ['url' => $url]);
@ -452,7 +453,7 @@ class Probe
*/ */
private static function getHideStatus(string $url): bool 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()) { if (!$curlResult->isSuccess()) {
return false; return false;
} }
@ -864,7 +865,7 @@ class Probe
public static function pollZot(string $url, array $data): array 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()) { if ($curlResult->isTimeout()) {
return $data; return $data;
} }
@ -963,7 +964,7 @@ class Probe
$curlResult = DI::httpClient()->get( $curlResult = DI::httpClient()->get(
$url, $url,
$type, $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) { } catch (\Throwable $e) {
Logger::notice($e->getMessage(), ['url' => $url, 'type' => $type, 'class' => get_class($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 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()) { if ($curlResult->isTimeout()) {
self::$isTimeout = true; self::$isTimeout = true;
return $data; return $data;
@ -1301,7 +1302,7 @@ class Probe
*/ */
private static function pollHcard(string $hcard_url, array $data, bool $dfrn = false): array 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()) { if ($curlResult->isTimeout()) {
self::$isTimeout = true; self::$isTimeout = true;
return []; return [];
@ -1577,7 +1578,7 @@ class Probe
$pubkey = substr($pubkey, 5); $pubkey = substr($pubkey, 5);
} }
} elseif (Strings::normaliseLink($pubkey) == 'http://') { } 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()) { if ($curlResult->isTimeout()) {
self::$isTimeout = true; self::$isTimeout = true;
return $short ? false : []; return $short ? false : [];
@ -1610,7 +1611,7 @@ class Probe
} }
// Fetch all additional data from the feed // 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()) { if ($curlResult->isTimeout()) {
self::$isTimeout = true; self::$isTimeout = true;
return []; return [];
@ -1662,7 +1663,7 @@ class Probe
*/ */
private static function pumpioProfileData(string $profile_link, string $baseurl): array 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())) { if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
return []; return [];
} }
@ -1879,7 +1880,7 @@ class Probe
private static function feed(string $url, bool $probe = true): array private static function feed(string $url, bool $probe = true): array
{ {
try { try {
$curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML); $curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML, [HttpClientOptions::REQUEST => HttpClientRequest::CONTACTINFO]);
} catch(\Throwable $e) { } catch(\Throwable $e) {
DI::logger()->info('Error requesting feed URL', ['url' => $url, 'exception' => $e]); DI::logger()->info('Error requesting feed URL', ['url' => $url, 'exception' => $e]);
return []; return [];
@ -2113,7 +2114,7 @@ class Probe
return ''; 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())) { if ($curlResult->isSuccess() && !empty($curlResult->getBodyString())) {
$noscrape = json_decode($curlResult->getBodyString(), true); $noscrape = json_decode($curlResult->getBodyString(), true);
@ -2189,7 +2190,7 @@ class Probe
private static function updateFromFeed(array $data): string private static function updateFromFeed(array $data): string
{ {
// Search for the newest entry in the feed // 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()) { if (!$curlResult->isSuccess() || !$curlResult->getBodyString()) {
return ''; return '';
} }

View file

@ -1082,7 +1082,7 @@ class Diaspora
Logger::info('Fetch post from ' . $source_url); 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) { if ($envelope) {
Logger::info('Envelope was fetched.'); Logger::info('Envelope was fetched.');
$x = self::verifyMagicEnvelope($envelope); $x = self::verifyMagicEnvelope($envelope);

View file

@ -41,6 +41,8 @@ use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images; use Friendica\Util\Images;
@ -734,7 +736,7 @@ class OStatus
private static function fetchRelated(string $related, string $related_uri, array $importer) private static function fetchRelated(string $related, string $related_uri, array $importer)
{ {
$stored = false; $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())) { if (!$curlResult->isSuccess() || empty($curlResult->getBodyString())) {
return; return;
@ -766,7 +768,7 @@ class OStatus
} }
} }
if ($atom_file != '') { 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()) { if ($curlResult->isSuccess()) {
Logger::info('Fetched XML for URI ' . $related_uri); Logger::info('Fetched XML for URI ' . $related_uri);
@ -778,7 +780,7 @@ class OStatus
// Workaround for older GNU Social servers // Workaround for older GNU Social servers
if (($xml == '') && strstr($related, '/notice/')) { 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()) { if ($curlResult->isSuccess()) {
Logger::info('GNU Social workaround to fetch XML for URI ' . $related_uri); 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 ;-) // Even more worse workaround for GNU Social ;-)
if ($xml == '') { if ($xml == '') {
$related_guess = self::convertHref($related_uri); $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()) { if ($curlResult->isSuccess()) {
Logger::info('GNU Social workaround 2 to fetch XML for URI ' . $related_uri); Logger::info('GNU Social workaround 2 to fetch XML for URI ' . $related_uri);

View file

@ -76,7 +76,7 @@ class Salmon
$ret[$x] = substr($ret[$x], 5); $ret[$x] = substr($ret[$x], 5);
} }
} elseif (Strings::normaliseLink($ret[$x]) == 'http://') { } 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]]); Logger::debug('Fetched public key', ['url' => $ret[$x]]);
} }
} }

View file

@ -58,6 +58,8 @@ use Friendica\Database\Database;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\PidFile; use Friendica\Util\PidFile;
@ -240,7 +242,7 @@ class ExAuth
$url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; $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()) { if (!$curlResult->isSuccess()) {
return false; return false;

View file

@ -26,6 +26,7 @@ use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use Friendica\Object\Image; use Friendica\Object\Image;
/** /**
@ -356,7 +357,7 @@ class Images
if (empty($img_str)) { if (empty($img_str)) {
try { try {
$img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4); $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4, '', HttpClientRequest::MEDIAVERIFIER);
} catch (\Exception $exception) { } catch (\Exception $exception) {
Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]); Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]);
return []; return [];

View file

@ -80,7 +80,7 @@ class Network
if (in_array(parse_url($url, PHP_URL_SCHEME), ['https', 'http'])) { if (in_array(parse_url($url, PHP_URL_SCHEME), ['https', 'http'])) {
$options = [HttpClientOptions::VERIFY => true, HttpClientOptions::TIMEOUT => $xrd_timeout, $options = [HttpClientOptions::VERIFY => true, HttpClientOptions::TIMEOUT => $xrd_timeout,
HttpClientOptions::REQUEST => HttpClientRequest::VERIFIER]; HttpClientOptions::REQUEST => HttpClientRequest::URLVERIFIER];
try { try {
$curlResult = DI::httpClient()->head($url, $options); $curlResult = DI::httpClient()->head($url, $options);
} catch (\Exception $e) { } catch (\Exception $e) {

View file

@ -234,7 +234,7 @@ class ParseUrl
} }
try { 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) { } catch (\Throwable $th) {
Logger::info('Exception when fetching', ['url' => $url, 'code' => $th->getCode(), 'message' => $th->getMessage()]); Logger::info('Exception when fetching', ['url' => $url, 'code' => $th->getCode(), 'message' => $th->getMessage()]);
return $siteinfo; return $siteinfo;

View file

@ -29,6 +29,7 @@ use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
use GuzzleHttp\Psr7\Uri; use GuzzleHttp\Psr7\Uri;
/* This class is used to verify the homepage link of a user profile. /* 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'); $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()) { if (!$curlResult->isSuccess()) {
Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]); Logger::notice('Could not cURL the homepage URL', ['owner homepage' => $owner['homepage']]);
return; return;

View file

@ -28,6 +28,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
/** /**
* Sends updated profile data to the directory * Sends updated profile data to the directory
@ -55,7 +56,7 @@ class Directory
Logger::info('Updating directory: ' . $arr['url']); Logger::info('Updating directory: ' . $arr['url']);
if (strlen($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; return;

View file

@ -165,7 +165,7 @@ class OnePoll
} }
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-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); unlink($cookiejar);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {

View file

@ -26,6 +26,7 @@ use Friendica\Core\Search;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
class PullDirectory class PullDirectory
{ {
@ -49,7 +50,7 @@ class PullDirectory
Logger::info('Synchronization started.', ['now' => $now, 'directory' => $directory]); 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)) { if (empty($result)) {
Logger::info('Directory server return empty result.', ['directory' => $directory]); Logger::info('Directory server return empty result.', ['directory' => $directory]);
return; return;

View file

@ -27,6 +27,7 @@ use Friendica\Core\Search;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
class SearchDirectory 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); $j = json_decode($x);
if (!empty($j->results)) { if (!empty($j->results)) {

View file

@ -26,6 +26,7 @@ use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
class UpdateServerDirectory class UpdateServerDirectory
{ {
@ -49,7 +50,7 @@ class UpdateServerDirectory
private static function discoverPoCo(array $gserver) 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)) { if (empty($result)) {
Logger::info('Empty result', ['url' => $gserver['url']]); Logger::info('Empty result', ['url' => $gserver['url']]);
return; return;
@ -82,7 +83,7 @@ class UpdateServerDirectory
private static function discoverMastodonDirectory(array $gserver) 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)) { if (empty($result)) {
Logger::info('Empty result', ['url' => $gserver['url']]); Logger::info('Empty result', ['url' => $gserver['url']]);
return; return;

View file

@ -27,6 +27,8 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Network\HTTPClient\Client\HttpClientAccept; 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\Network;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -44,7 +46,7 @@ class UpdateServerPeers
return; 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())) { if (!$ret->isSuccess() || empty($ret->getBodyString())) {
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]); Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
return; return;