Merge pull request #11382 from annando/accept-2

Some more "accept" parameters are added
This commit is contained in:
Philipp 2022-03-30 17:14:17 +02:00 committed by GitHub
commit db60557a4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 136 additions and 80 deletions

View file

@ -24,6 +24,8 @@ use Friendica\Core\Protocol;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\APContact; use Friendica\Model\APContact;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
function ostatus_subscribe_content(App $a) function ostatus_subscribe_content(App $a)
@ -57,7 +59,7 @@ function ostatus_subscribe_content(App $a)
$api = $contact['baseurl'] . '/api/'; $api = $contact['baseurl'] . '/api/';
// Fetching friends // Fetching friends
$curlResult = DI::httpClient()->get($api . 'statuses/friends.json?screen_name=' . $contact['nick']); $curlResult = DI::httpClient()->get($api . 'statuses/friends.json?screen_name=' . $contact['nick'], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact'); DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');

View file

@ -27,6 +27,8 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Strings; use Friendica\Util\Strings;
function redir_init(App $a) { function redir_init(App $a) {
@ -142,7 +144,7 @@ function redir_magic($a, $cid, $url)
} }
// Test for magic auth on the target system // Test for magic auth on the target system
$serverret = DI::httpClient()->get($basepath . '/magic'); $serverret = DI::httpClient()->head($basepath . '/magic', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if ($serverret->isSuccess()) { if ($serverret->isSuccess()) {
$separator = strpos($target_url, '?') ? '&' : '?'; $separator = strpos($target_url, '?') ? '&' : '?';
$target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url); $target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);

View file

@ -32,6 +32,7 @@ use Friendica\Core\Renderer;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
@ -97,7 +98,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, 15, 'text/*'); $html_text = DI::httpClient()->fetch($embedurl, 15, HttpClient::ACCEPT_HTML);
if (!empty($html_text)) { if (!empty($html_text)) {
$dom = new DOMDocument(); $dom = new DOMDocument();
if (@$dom->loadHTML($html_text)) { if (@$dom->loadHTML($html_text)) {

View file

@ -39,6 +39,7 @@ use Friendica\Model\Event;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
@ -501,11 +502,13 @@ class BBCode
continue; continue;
} }
$curlResult = DI::httpClient()->get($mtch[1]); $curlResult = DI::httpClient()->get($mtch[1], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_IMAGE]);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
continue; continue;
} }
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $mtch[1]]);
$i = $curlResult->getBody(); $i = $curlResult->getBody();
$type = $curlResult->getContentType(); $type = $curlResult->getContentType();
$type = Images::getMimeTypeByData($i, $mtch[1], $type); $type = Images::getMimeTypeByData($i, $mtch[1], $type);
@ -1096,7 +1099,7 @@ class BBCode
$attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8'); $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
} }
$img_str = '<img src="' . $img_str = '<img src="' .
self::proxyUrl($match[2], $simplehtml, $uriid) . '"'; self::proxyUrl($match[2], $simplehtml, $uriid) . '"';
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
if (!empty($value)) { if (!empty($value)) {
@ -1201,7 +1204,7 @@ class BBCode
$text = DI::cache()->get($cache_key); $text = DI::cache()->get($cache_key);
if (is_null($text)) { if (is_null($text)) {
$curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout'), HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; $mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
} else { } else {
@ -1214,7 +1217,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]); $body = DI::httpClient()->fetch($match[1], 0, HttpClient::ACCEPT_HTML);
if (empty($body)) { if (empty($body)) {
DI::cache()->set($cache_key, $text); DI::cache()->set($cache_key, $text);
return $text; return $text;
@ -1272,7 +1275,7 @@ class BBCode
return $text; return $text;
} }
$curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout'), HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; $mimetype = $curlResult->getHeader('Content-Type')[0] ?? '';
} else { } else {
@ -1290,7 +1293,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]); $body = DI::httpClient()->fetch($match[1], 0, HttpClient::ACCEPT_HTML);
if (empty($body)) { if (empty($body)) {
DI::cache()->set($cache_key, $text); DI::cache()->set($cache_key, $text);
return $text; return $text;
@ -1780,7 +1783,7 @@ class BBCode
$text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . DI::l10n()->t('Image/photo') . '" />', $text); $text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . DI::l10n()->t('Image/photo') . '" />', $text);
$text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . DI::l10n()->t('Image/photo') . '" />', $text); $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . DI::l10n()->t('Image/photo') . '" />', $text);
$text = self::convertImages($text, $simple_html, $uriid); $text = self::convertImages($text, $simple_html, $uriid);
$text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . DI::l10n()->t('Encrypted content') . '" /><br>', $text); $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
@ -1894,7 +1897,7 @@ class BBCode
} else { } else {
$text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text); $text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
} }
if (!$for_plaintext) { if (!$for_plaintext) {
if (in_array($simple_html, [self::OSTATUS, self::API, self::ACTIVITYPUB])) { if (in_array($simple_html, [self::OSTATUS, self::API, self::ACTIVITYPUB])) {
$text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);

View file

@ -23,6 +23,7 @@ namespace Friendica\Core;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Object\Search\ContactResult; use Friendica\Object\Search\ContactResult;
@ -122,7 +123,7 @@ class Search
$searchUrl .= '&page=' . $page; $searchUrl .= '&page=' . $page;
} }
$resultJson = DI::httpClient()->fetch($searchUrl, 0, 'application/json'); $resultJson = DI::httpClient()->fetch($searchUrl, 0, HttpClient::ACCEPT_JSON);
$results = json_decode($resultJson, true); $results = json_decode($resultJson, true);
@ -228,7 +229,7 @@ class Search
$return = Contact::searchByName($search, $mode); $return = Contact::searchByName($search, $mode);
} else { } else {
$p = $page > 1 ? 'p=' . $page : ''; $p = $page > 1 ? 'p=' . $page : '';
$curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), [HttpClientOptions::ACCEPT_CONTENT => ['application/json']]); $curlResult = DI::httpClient()->get(self::getGlobalDirectory() . '/search/people?' . $p . '&q=' . urlencode($search), [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$searchResult = json_decode($curlResult->getBody(), true); $searchResult = json_decode($curlResult->getBody(), true);
if (!empty($searchResult['profiles'])) { if (!empty($searchResult['profiles'])) {

View file

@ -22,8 +22,11 @@
namespace Friendica\Core\Storage\Type; namespace Friendica\Core\Storage\Type;
use Exception; use Exception;
use Friendica\Core\Logger;
use Friendica\Core\Storage\Exception\ReferenceStorageException; use Friendica\Core\Storage\Exception\ReferenceStorageException;
use Friendica\Core\Storage\Capability\ICanReadFromStorage; use Friendica\Core\Storage\Capability\ICanReadFromStorage;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
/** /**
@ -52,11 +55,12 @@ class ExternalResource implements ICanReadFromStorage
} }
try { try {
$fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, ['accept_content' => []]); $fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_IMAGE]]);
} catch (Exception $exception) { } catch (Exception $exception) {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception); throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
} }
if ($fetchResult->isSuccess()) { if ($fetchResult->isSuccess()) {
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]);
return $fetchResult->getBody(); return $fetchResult->getBody();
} else { } else {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBody())); throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBody()));

View file

@ -1946,7 +1946,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)); $curlResult = DI::httpClient()->fetch('https://the-federation.info/graphql?query=' . urlencode($query), 0, HttpClient::ACCEPT_JSON);
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'])) {

View file

@ -32,6 +32,8 @@ use Friendica\Core\Storage\Exception\InvalidClassStorageException;
use Friendica\Core\Storage\Exception\ReferenceStorageException; use Friendica\Core\Storage\Exception\ReferenceStorageException;
use Friendica\Core\Storage\Exception\StorageException; use Friendica\Core\Storage\Exception\StorageException;
use Friendica\Core\Storage\Type\SystemResource; use Friendica\Core\Storage\Type\SystemResource;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images; use Friendica\Util\Images;
@ -497,7 +499,8 @@ class Photo
$filename = basename($image_url); $filename = basename($image_url);
if (!empty($image_url)) { if (!empty($image_url)) {
$ret = DI::httpClient()->get($image_url); $ret = DI::httpClient()->get($image_url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_IMAGE]);
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
$img_str = $ret->getBody(); $img_str = $ret->getBody();
$type = $ret->getContentType(); $type = $ret->getContentType();
} else { } else {
@ -912,7 +915,8 @@ class Photo
{ {
$filename = basename($image_url); $filename = basename($image_url);
if (!empty($image_url)) { if (!empty($image_url)) {
$ret = DI::httpClient()->get($image_url); $ret = DI::httpClient()->get($image_url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_IMAGE]);
Logger::debug('Got picture', ['Content-Type' => $ret->getHeader('Content-Type'), 'url' => $image_url]);
$img_str = $ret->getBody(); $img_str = $ret->getBody();
$type = $ret->getContentType(); $type = $ret->getContentType();
} else { } else {

View file

@ -26,6 +26,7 @@ use Friendica\Core\System;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
@ -96,11 +97,11 @@ class Link
return $url . $id; return $url . $id;
} }
private static function fetchMimeType(string $url) private static function fetchMimeType(string $url, string $accept = HttpClient::ACCEPT_DEFAULT)
{ {
$timeout = DI::config()->get('system', 'xrd_timeout'); $timeout = DI::config()->get('system', 'xrd_timeout');
$curlResult = DI::httpClient()->head($url, [HttpClientOptions::TIMEOUT => $timeout]); $curlResult = DI::httpClient()->head($url, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
if (empty($media['mimetype'])) { if (empty($media['mimetype'])) {
return $curlResult->getHeader('Content-Type')[0] ?? ''; return $curlResult->getHeader('Content-Type')[0] ?? '';

View file

@ -30,6 +30,7 @@ use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Images; use Friendica\Util\Images;
use Friendica\Util\Network; use Friendica\Util\Network;
@ -168,11 +169,11 @@ class Media
// Fetch the mimetype or size if missing. // Fetch the mimetype or size if missing.
if (empty($media['mimetype']) || empty($media['size'])) { if (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::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
// 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)) {
$curlResult = DI::httpClient()->get($media['url'], [HttpClientOptions::TIMEOUT => $timeout]); $curlResult = DI::httpClient()->get($media['url'], [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
} }
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {

View file

@ -35,6 +35,8 @@ use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
@ -749,7 +751,7 @@ class Profile
$magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request; $magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request;
// We have to check if the remote server does understand /magic without invoking something // We have to check if the remote server does understand /magic without invoking something
$serverret = DI::httpClient()->get($basepath . '/magic'); $serverret = DI::httpClient()->head($basepath . '/magic', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if ($serverret->isSuccess()) { if ($serverret->isSuccess()) {
Logger::info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path); Logger::info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path);
System::externalRedirect($magic_path); System::externalRedirect($magic_path);

View file

@ -34,6 +34,8 @@ use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Security\TwoFactor\Model\AppSpecificPassword; use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Object\Image; use Friendica\Object\Image;
@ -1150,8 +1152,9 @@ class User
$photo_failure = false; $photo_failure = false;
$filename = basename($photo); $filename = basename($photo);
$curlResult = DI::httpClient()->get($photo); $curlResult = DI::httpClient()->get($photo, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_IMAGE]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
$img_str = $curlResult->getBody(); $img_str = $curlResult->getBody();
$type = $curlResult->getContentType(); $type = $curlResult->getContentType();
} else { } else {

View file

@ -32,6 +32,8 @@ use Friendica\DI;
use Friendica\Core\Config\Factory\Config; use Friendica\Core\Config\Factory\Config;
use Friendica\Model\Register; use Friendica\Model\Register;
use Friendica\Module\BaseAdmin; use Friendica\Module\BaseAdmin;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPException\ServiceUnavailableException; use Friendica\Network\HTTPException\ServiceUnavailableException;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -248,7 +250,7 @@ class Summary extends BaseAdmin
private static function checkSelfHostMeta() private static function checkSelfHostMeta()
{ {
// Fetch the host-meta to check if this really is a vital server // Fetch the host-meta to check if this really is a vital server
return DI::httpClient()->get(DI::baseUrl()->get() . '/.well-known/host-meta')->isSuccess(); return DI::httpClient()->get(DI::baseUrl()->get() . '/.well-known/host-meta', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_XRD_XML])->isSuccess();
} }
} }

View file

@ -28,6 +28,7 @@ use Friendica\Core\Renderer;
use Friendica\Model; 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\HttpClient;
use Friendica\Protocol; use Friendica\Protocol;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -60,7 +61,7 @@ class Feed extends BaseModule
$contact = Model\Contact::getByURLForUser($url, local_user(), null); $contact = Model\Contact::getByURLForUser($url, local_user(), null);
$xml = $this->httpClient->fetch($contact['poll']); $xml = $this->httpClient->fetch($contact['poll'], 0, HttpClient::ACCEPT_FEED_XML);
$import_result = Protocol\Feed::import($xml); $import_result = Protocol\Feed::import($xml);

View file

@ -29,6 +29,7 @@ use Friendica\Database\Database;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;

View file

@ -32,6 +32,7 @@ use Friendica\Model\Profile;
use Friendica\Core\Storage\Type\ExternalResource; use Friendica\Core\Storage\Type\ExternalResource;
use Friendica\Core\Storage\Type\SystemResource; use Friendica\Core\Storage\Type\SystemResource;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\NotModifiedException; use Friendica\Network\HTTPException\NotModifiedException;
use Friendica\Object\Image; use Friendica\Object\Image;
@ -308,7 +309,7 @@ class Photo extends BaseModule
} }
$mimetext = ''; $mimetext = '';
if (!empty($url)) { if (!empty($url)) {
$mime = ParseUrl::getContentType($url); $mime = ParseUrl::getContentType($url, HttpClient::ACCEPT_IMAGE);
if (!empty($mime)) { if (!empty($mime)) {
$mimetext = $mime[0] . '/' . $mime[1]; $mimetext = $mime[0] . '/' . $mime[1];
} else { } else {
@ -317,6 +318,8 @@ class Photo extends BaseModule
if (!empty($mimetext) && ($mime[0] != 'image') && ($mimetext != 'application/octet-stream')) { if (!empty($mimetext) && ($mime[0] != 'image') && ($mimetext != 'application/octet-stream')) {
Logger::info('Unexpected Content-Type', ['mime' => $mimetext, 'url' => $url]); Logger::info('Unexpected Content-Type', ['mime' => $mimetext, 'url' => $url]);
$mimetext = ''; $mimetext = '';
} if (!empty($mimetext)) {
Logger::debug('Expected Content-Type', ['mime' => $mimetext, 'url' => $url]);
} }
} }
if (empty($mimetext)) { if (empty($mimetext)) {

View file

@ -25,6 +25,8 @@ use Friendica\BaseModule;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPException\NotModifiedException; use Friendica\Network\HTTPException\NotModifiedException;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\HTTPSignature; use Friendica\Util\HTTPSignature;
@ -81,7 +83,7 @@ class Proxy extends BaseModule
$request['url'] = str_replace(' ', '+', $request['url']); $request['url'] = str_replace(' ', '+', $request['url']);
// Fetch the content with the local user // Fetch the content with the local user
$fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), ['accept_content' => [], 'timeout' => 10]); $fetchResult = HTTPSignature::fetchRaw($request['url'], local_user(), [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_IMAGE], 'timeout' => 10]);
$img_str = $fetchResult->getBody(); $img_str = $fetchResult->getBody();
if (!$fetchResult->isSuccess() || empty($img_str)) { if (!$fetchResult->isSuccess() || empty($img_str)) {
@ -90,6 +92,8 @@ class Proxy extends BaseModule
// stop. // stop.
} }
Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => local_user(), 'image' => $request['url']]);
$mime = Images::getMimeTypeByData($img_str); $mime = Images::getMimeTypeByData($img_str);
$image = new Image($img_str, $mime); $image = new Image($img_str, $mime);

View file

@ -44,17 +44,20 @@ use Psr\Log\LoggerInterface;
class HttpClient implements ICanSendHttpRequests class HttpClient implements ICanSendHttpRequests
{ {
/** @var string Default value for "Accept" header */ /** @var string Default value for "Accept" header */
const ACCEPT_DEFAULT = '*/*'; const ACCEPT_DEFAULT = '*/*';
const ACCEPT_ATOM_XML = 'application/atom+xml,text/xml;q=0.9,*/*;q=0.8'; const ACCEPT_ATOM_XML = 'application/atom+xml,text/xml;q=0.9,*/*;q=0.8';
const ACCEPT_FEED_XML = 'application/atom+xml,application/rss+xml;q=0.9,application/rdf+xml;q=0.8,text/xml;q=0.7,*/*;q=0.6'; const ACCEPT_FEED_XML = 'application/atom+xml,application/rss+xml;q=0.9,application/rdf+xml;q=0.8,text/xml;q=0.7,*/*;q=0.6';
const ACCEPT_HTML = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; const ACCEPT_HTML = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
const ACCEPT_IMAGE = 'image/png,image/jpeg,image/gif,image/*;q=0.9,*/*;q=0.8'; const ACCEPT_IMAGE = 'image/png,image/jpeg,image/gif,image/*;q=0.9,*/*;q=0.8';
const ACCEPT_JRD_JSON = 'application/jrd+json,application/json;q=0.9'; const ACCEPT_JRD_JSON = 'application/jrd+json,application/json;q=0.9';
const ACCEPT_JSON = 'application/json,*/*;q=0.9'; const ACCEPT_JSON = 'application/json,*/*;q=0.9';
const ACCEPT_JSON_AS = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; const ACCEPT_JSON_AS = 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"';
const ACCEPT_RSS_XML = 'application/rss+xml,text/xml;q=0.9,*/*;q=0.8'; const ACCEPT_MAGIC = 'application/magic-envelope+xml';
const ACCEPT_VIDEO = 'video/mp4,video/*;q=0.9,*/*;q=0.8'; const ACCEPT_MAGIC_KEY = 'application/magic-public-key';
const ACCEPT_XRD_XML = 'application/xrd+xml,text/xml;q=0.9,*/*;q=0.8'; const ACCEPT_RSS_XML = 'application/rss+xml,text/xml;q=0.9,*/*;q=0.8';
const ACCEPT_TEXT = 'text/plain,text/*;q=0.9,*/*;q=0.8';
const ACCEPT_VIDEO = 'video/mp4,video/*;q=0.9,*/*;q=0.8';
const ACCEPT_XRD_XML = 'application/xrd+xml,text/xml;q=0.9,*/*;q=0.8';
/** @var LoggerInterface */ /** @var LoggerInterface */
private $logger; private $logger;
@ -265,9 +268,9 @@ class HttpClient implements ICanSendHttpRequests
return $this->get( return $this->get(
$url, $url,
[ [
'timeout' => $timeout, HttpClientOptions::TIMEOUT => $timeout,
'accept_content' => $accept_content, HttpClientOptions::ACCEPT_CONTENT => $accept_content,
'cookiejar' => $cookiejar HttpClientOptions::COOKIEJAR => $cookiejar
] ]
); );
} }

View file

@ -170,7 +170,7 @@ class Probe
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]); Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]);
$xrd = null; $xrd = null;
$curlResult = DI::httpClient()->get($ssl_url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => ['application/xrd+xml']]); $curlResult = DI::httpClient()->get($ssl_url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_XRD_XML]);
$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->getBody(); $xml = $curlResult->getBody();
@ -187,7 +187,7 @@ class Probe
} }
if (!is_object($xrd) && !empty($url)) { if (!is_object($xrd) && !empty($url)) {
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => ['application/xrd+xml']]); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_XRD_XML]);
$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]);
@ -429,7 +429,7 @@ class Probe
*/ */
private static function getHideStatus($url) private static function getHideStatus($url)
{ {
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return false;
} }
@ -834,7 +834,7 @@ class Probe
public static function pollZot($url, $data) public static function pollZot($url, $data)
{ {
$curlResult = DI::httpClient()->get($url); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
return $data; return $data;
} }
@ -931,7 +931,7 @@ class Probe
{ {
$xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20); $xrd_timeout = DI::config()->get('system', 'xrd_timeout', 20);
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => [$type]]); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => $type]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -1000,7 +1000,7 @@ class Probe
*/ */
private static function pollNoscrape($noscrape_url, $data) private static function pollNoscrape($noscrape_url, $data)
{ {
$curlResult = DI::httpClient()->get($noscrape_url); $curlResult = DI::httpClient()->get($noscrape_url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return $data; return $data;
@ -1266,7 +1266,7 @@ class Probe
*/ */
private static function pollHcard($hcard_url, $data, $dfrn = false) private static function pollHcard($hcard_url, $data, $dfrn = false)
{ {
$curlResult = DI::httpClient()->get($hcard_url); $curlResult = DI::httpClient()->get($hcard_url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -1527,11 +1527,12 @@ 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); $curlResult = DI::httpClient()->get($pubkey, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_MAGIC_KEY]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return $short ? false : []; return $short ? false : [];
} }
Logger::debug('Fetched public key', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $pubkey]);
$pubkey = $curlResult->getBody(); $pubkey = $curlResult->getBody();
} }
@ -1561,7 +1562,7 @@ class Probe
} }
// Fetch all additional data from the feed // Fetch all additional data from the feed
$curlResult = DI::httpClient()->get($data["poll"]); $curlResult = DI::httpClient()->get($data["poll"], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_FEED_XML]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -1613,7 +1614,7 @@ class Probe
*/ */
private static function pumpioProfileData($profile_link) private static function pumpioProfileData($profile_link)
{ {
$curlResult = DI::httpClient()->get($profile_link); $curlResult = DI::httpClient()->get($profile_link, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return []; return [];
} }
@ -1826,7 +1827,7 @@ class Probe
*/ */
private static function feed($url, $probe = true) private static function feed($url, $probe = true)
{ {
$curlResult = DI::httpClient()->get($url); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_FEED_XML]);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
self::$istimeout = true; self::$istimeout = true;
return []; return [];
@ -2048,7 +2049,7 @@ class Probe
return ''; return '';
} }
$curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick']); $curlResult = DI::httpClient()->get($gserver['noscrape'] . '/' . $data['nick'], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) { if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
$noscrape = json_decode($curlResult->getBody(), true); $noscrape = json_decode($curlResult->getBody(), true);
@ -2123,7 +2124,7 @@ class Probe
private static function updateFromFeed(array $data) private static function updateFromFeed(array $data)
{ {
// Search for the newest entry in the feed // Search for the newest entry in the feed
$curlResult = DI::httpClient()->get($data['poll']); $curlResult = DI::httpClient()->get($data['poll'], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if (!$curlResult->isSuccess() || !$curlResult->getBody()) { if (!$curlResult->isSuccess() || !$curlResult->getBody()) {
return ''; return '';
} }

View file

@ -41,6 +41,7 @@ use Friendica\Model\Mail;
use Friendica\Model\Post; 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\HttpClient;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -1059,7 +1060,7 @@ class Diaspora
Logger::info("Fetch post from ".$source_url); Logger::info("Fetch post from ".$source_url);
$envelope = DI::httpClient()->fetch($source_url); $envelope = DI::httpClient()->fetch($source_url, 0, HttpClient::ACCEPT_MAGIC);
if ($envelope) { if ($envelope) {
Logger::info("Envelope was fetched."); Logger::info("Envelope was fetched.");
$x = self::verifyMagicEnvelope($envelope); $x = self::verifyMagicEnvelope($envelope);

View file

@ -38,6 +38,7 @@ use Friendica\Model\ItemURI;
use Friendica\Model\Post; 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\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -731,7 +732,7 @@ class OStatus
self::$conv_list[$conversation] = true; self::$conv_list[$conversation] = true;
$curlResult = DI::httpClient()->get($conversation, [HttpClientOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]); $curlResult = DI::httpClient()->get($conversation, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return; return;
@ -761,7 +762,7 @@ class OStatus
} }
} }
if ($file != '') { if ($file != '') {
$conversation_atom = DI::httpClient()->get($attribute['href']); $conversation_atom = DI::httpClient()->get($attribute['href'], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if ($conversation_atom->isSuccess()) { if ($conversation_atom->isSuccess()) {
$xml = $conversation_atom->getBody(); $xml = $conversation_atom->getBody();
@ -875,7 +876,7 @@ class OStatus
return; return;
} }
$curlResult = DI::httpClient()->get($self); $curlResult = DI::httpClient()->get($self, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return; return;
@ -925,7 +926,7 @@ class OStatus
} }
$stored = false; $stored = false;
$curlResult = DI::httpClient()->get($related, [HttpClientOptions::ACCEPT_CONTENT => ['application/atom+xml', 'text/html']]); $curlResult = DI::httpClient()->get($related, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return; return;
@ -957,7 +958,7 @@ class OStatus
} }
} }
if ($atom_file != '') { if ($atom_file != '') {
$curlResult = DI::httpClient()->get($atom_file); $curlResult = DI::httpClient()->get($atom_file, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
Logger::info('Fetched XML for URI ' . $related_uri); Logger::info('Fetched XML for URI ' . $related_uri);
@ -969,7 +970,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'); $curlResult = DI::httpClient()->get(str_replace('/notice/', '/api/statuses/show/', $related) . '.atom', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
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);
@ -980,7 +981,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'); $curlResult = DI::httpClient()->get(str_replace('/notice/', '/api/statuses/show/', $related_guess) . '.atom', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
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

@ -23,6 +23,7 @@ namespace Friendica\Protocol;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Crypto; use Friendica\Util\Crypto;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -72,7 +73,8 @@ 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]); $ret[$x] = DI::httpClient()->fetch($ret[$x], 0, HttpClient::ACCEPT_MAGIC_KEY);
Logger::debug('Fetched public key', ['url' => $ret[$x]]);
} }
} }
} }

View file

@ -57,6 +57,8 @@ use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\PidFile; use Friendica\Util\PidFile;
@ -239,7 +241,7 @@ class ExAuth
$url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user;
$curlResult = DI::httpClient()->get($url); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
return false; return false;

View file

@ -416,7 +416,7 @@ class HTTPSignature
* @return \Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses CurlResult * @return \Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses CurlResult
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function fetchRaw($request, $uid = 0, $opts = ['accept_content' => [HttpClient::ACCEPT_JSON_AS]]) public static function fetchRaw($request, $uid = 0, $opts = [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_JSON_AS]])
{ {
$header = []; $header = [];

View file

@ -24,6 +24,7 @@ namespace Friendica\Util;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Network\HTTPClient\Client\HttpClient;
/** /**
* Image utilities * Image utilities
@ -219,7 +220,7 @@ class Images
} }
if (empty($img_str)) { if (empty($img_str)) {
$img_str = DI::httpClient()->fetch($url, 4); $img_str = DI::httpClient()->fetch($url, 4, HttpClient::ACCEPT_IMAGE);
} }
if (!$img_str) { if (!$img_str) {

View file

@ -29,6 +29,7 @@ use Friendica\Core\Logger;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
@ -54,16 +55,17 @@ class ParseUrl
/** /**
* Fetch the content type of the given url * Fetch the content type of the given url
* @param string $url URL of the page * @param string $url URL of the page
* @param string $accept content-type to accept
* @return array content type * @return array content type
*/ */
public static function getContentType(string $url) public static function getContentType(string $url, string $accept = HttpClient::ACCEPT_DEFAULT)
{ {
$curlResult = DI::httpClient()->head($url); $curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => $accept]);
// 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)) {
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::ACCEPT_CONTENT => $accept]);
} }
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
@ -220,7 +222,7 @@ class ParseUrl
return $siteinfo; return $siteinfo;
} }
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]); $curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) { if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]); Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]);
return $siteinfo; return $siteinfo;

View file

@ -24,6 +24,7 @@ namespace Friendica\Worker;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
/** /**
* Check the git repository VERSION file and save the version to the DB * Check the git repository VERSION file and save the version to the DB
@ -54,7 +55,7 @@ class CheckVersion
Logger::info("Checking VERSION from: ".$checked_url); Logger::info("Checking VERSION from: ".$checked_url);
// fetch the VERSION file // fetch the VERSION file
$gitversion = DBA::escape(trim(DI::httpClient()->fetch($checked_url))); $gitversion = DBA::escape(trim(DI::httpClient()->fetch($checked_url, 0, HttpClient::ACCEPT_TEXT)));
Logger::notice("Upstream VERSION is: ".$gitversion); Logger::notice("Upstream VERSION is: ".$gitversion);
DI::config()->set('system', 'git_friendica_version', $gitversion); DI::config()->set('system', 'git_friendica_version', $gitversion);

View file

@ -26,6 +26,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Network\HTTPClient\Client\HttpClient;
/** /**
* Sends updated profile data to the directory * Sends updated profile data to the directory
@ -53,7 +54,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'])); DI::httpClient()->fetch($dir . '?url=' . bin2hex($arr['url']), 0, HttpClient::ACCEPT_HTML);
} }
return; return;

View file

@ -24,6 +24,7 @@ namespace Friendica\Worker;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Nodeinfo as ModelNodeInfo; use Friendica\Model\Nodeinfo as ModelNodeInfo;
use Friendica\Network\HTTPClient\Client\HttpClient;
class NodeInfo class NodeInfo
{ {
@ -34,7 +35,7 @@ class NodeInfo
// Now trying to register // Now trying to register
$url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname(); $url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname();
Logger::debug('Check registering url', ['url' => $url]); Logger::debug('Check registering url', ['url' => $url]);
$ret = DI::httpClient()->fetch($url); $ret = DI::httpClient()->fetch($url, 0, HttpClient::ACCEPT_HTML);
Logger::debug('Check registering answer', ['answer' => $ret]); Logger::debug('Check registering answer', ['answer' => $ret]);
Logger::info('end'); Logger::info('end');
} }

View file

@ -155,7 +155,7 @@ class OnePoll
} }
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-'); $cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-');
$curlResult = DI::httpClient()->get($contact['poll'], [HttpClientOptions::COOKIEJAR => $cookiejar], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_FEED_XML]); $curlResult = DI::httpClient()->get($contact['poll'], [HttpClientOptions::COOKIEJAR => $cookiejar, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_FEED_XML]);
unlink($cookiejar); unlink($cookiejar);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {

View file

@ -24,6 +24,7 @@ namespace Friendica\Worker;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClient;
class PullDirectory class PullDirectory
{ {
@ -47,7 +48,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); $result = DI::httpClient()->fetch($directory . '/sync/pull/since/' . $now, 0, HttpClient::ACCEPT_JSON);
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

@ -26,6 +26,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Search; use Friendica\Core\Search;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Network\HTTPClient\Client\HttpClient;
class SearchDirectory class SearchDirectory
{ {
@ -46,7 +47,7 @@ class SearchDirectory
} }
} }
$x = DI::httpClient()->fetch(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search)); $x = DI::httpClient()->fetch(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search), 0, HttpClient::ACCEPT_JSON);
$j = json_decode($x); $j = json_decode($x);
if (!empty($j->results)) { if (!empty($j->results)) {

View file

@ -26,6 +26,7 @@ use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Network\HTTPClient\Client\HttpClient;
class UpdateServerDirectory class UpdateServerDirectory
{ {
@ -45,7 +46,7 @@ class UpdateServerDirectory
private static function discoverPoCo(array $gserver) private static function discoverPoCo(array $gserver)
{ {
$result = DI::httpClient()->fetch($gserver['poco'] . '?fields=urls'); $result = DI::httpClient()->fetch($gserver['poco'] . '?fields=urls', 0, HttpClient::ACCEPT_JSON);
if (empty($result)) { if (empty($result)) {
Logger::info('Empty result', ['url' => $gserver['url']]); Logger::info('Empty result', ['url' => $gserver['url']]);
return; return;
@ -78,7 +79,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'); $result = DI::httpClient()->fetch($gserver['url'] . '/api/v1/directory?order=new&local=true&limit=200&offset=0', 0, HttpClient::ACCEPT_JSON);
if (empty($result)) { if (empty($result)) {
Logger::info('Empty result', ['url' => $gserver['url']]); Logger::info('Empty result', ['url' => $gserver['url']]);
return; return;

View file

@ -25,6 +25,8 @@ use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\GServer; use Friendica\Model\GServer;
use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Strings; use Friendica\Util\Strings;
class UpdateServerPeers class UpdateServerPeers
@ -35,7 +37,7 @@ class UpdateServerPeers
*/ */
public static function execute(string $url) public static function execute(string $url)
{ {
$ret = DI::httpClient()->get($url . '/api/v1/instance/peers'); $ret = DI::httpClient()->get($url . '/api/v1/instance/peers', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$ret->isSuccess() || empty($ret->getBody())) { if (!$ret->isSuccess() || empty($ret->getBody())) {
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;