mirror of
https://github.com/friendica/friendica
synced 2024-12-22 22:00:16 +00:00
Request type set for all HTTP requests
This commit is contained in:
parent
d788cb82cc
commit
5751e024c0
30 changed files with 129 additions and 90 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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'])) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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 '';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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]]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 [];
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue