use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Protocol\ActivityPub;
function ostatus_subscribe_content(App $a)
$api = $contact['baseurl'] . '/api/';
// 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()) {
DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Strings;
function redir_init(App $a) {
}
// Test for magic auth on the target system
- $serverret = DI::httpClient()->get($basepath . '/magic');
+ $serverret = DI::httpClient()->get($basepath . '/magic', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
if ($serverret->isSuccess()) {
$separator = strpos($target_url, '?') ? '&' : '?';
$target_url .= $separator . 'zrl=' . urlencode($visitor) . '&addr=' . urlencode($contact_url);
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
if (!in_array($ext, $noexts)) {
// 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)) {
$dom = new DOMDocument();
if (@$dom->loadHTML($html_text)) {
use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\Tag;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Object\Image;
use Friendica\Protocol\Activity;
continue;
}
- $curlResult = DI::httpClient()->get($mtch[1]);
+ $curlResult = DI::httpClient()->get($mtch[1], [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_IMAGE]);
if (!$curlResult->isSuccess()) {
continue;
}
+ Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $mtch[1]]);
+
$i = $curlResult->getBody();
$type = $curlResult->getContentType();
$type = Images::getMimeTypeByData($i, $mtch[1], $type);
$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) . '"';
foreach ($attributes as $key => $value) {
if (!empty($value)) {
$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]);
+ $body = DI::httpClient()->fetch($match[1], 0, HttpClient::ACCEPT_HTML);
if (empty($body)) {
DI::cache()->set($cache_key, $text);
return $text;
}
// 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)) {
DI::cache()->set($cache_key, $text);
return $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 = 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);
} else {
$text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
}
-
+
if (!$for_plaintext) {
if (in_array($simple_html, [self::OSTATUS, self::API, self::ACTIVITYPUB])) {
$text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
use Friendica\DI;
use Friendica\Model\Contact;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Object\Search\ContactResult;
$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);
$return = Contact::searchByName($search, $mode);
} else {
$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()) {
$searchResult = json_decode($curlResult->getBody(), true);
if (!empty($searchResult['profiles'])) {
namespace Friendica\Core\Storage\Type;
use Exception;
+use Friendica\Core\Logger;
use Friendica\Core\Storage\Exception\ReferenceStorageException;
use Friendica\Core\Storage\Capability\ICanReadFromStorage;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Util\HTTPSignature;
/**
}
try {
- $fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, ['accept_content' => []]);
+ $fetchResult = HTTPSignature::fetchRaw($data->url, $data->uid, ['accept_content' => [HttpClient::ACCEPT_IMAGE]]);
} catch (Exception $exception) {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $exception->getCode(), $exception);
}
if ($fetchResult->isSuccess()) {
+ Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => $data->uid, 'url' => $data->url]);
return $fetchResult->getBody();
} else {
throw new ReferenceStorageException(sprintf('External resource failed to get %s', $reference), $fetchResult->getReturnCode(), new Exception($fetchResult->getBody()));
$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));
+ $curlResult = DI::httpClient()->fetch('https://the-federation.info/graphql?query=' . urlencode($query), 0, HttpClient::ACCEPT_JSON);
if (!empty($curlResult)) {
$data = json_decode($curlResult, true);
if (!empty($data['data']['nodes'])) {
use Friendica\Core\Storage\Exception\ReferenceStorageException;
use Friendica\Core\Storage\Exception\StorageException;
use Friendica\Core\Storage\Type\SystemResource;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Object\Image;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
$filename = basename($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();
$type = $ret->getContentType();
} else {
{
$filename = basename($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();
$type = $ret->getContentType();
} else {
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Post;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Images;
use Friendica\Util\Network;
// Fetch the mimetype or size if missing.
if (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::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
// Workaround for systems that can't handle a HEAD request
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()) {
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Diaspora;
$magic_path = $basepath . '/magic' . '?owa=1&dest=' . $dest . '&' . $addr_request;
// We have to check if the remote server does understand /magic without invoking something
- $serverret = DI::httpClient()->get($basepath . '/magic');
+ $serverret = DI::httpClient()->get($basepath . '/magic', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
if ($serverret->isSuccess()) {
Logger::info('Doing magic auth for visitor ' . $my_url . ' to ' . $magic_path);
System::externalRedirect($magic_path);
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
use Friendica\Network\HTTPException;
use Friendica\Object\Image;
$photo_failure = false;
$filename = basename($photo);
- $curlResult = DI::httpClient()->get($photo);
+ $curlResult = DI::httpClient()->get($photo, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_IMAGE]);
if ($curlResult->isSuccess()) {
+ Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]);
$img_str = $curlResult->getBody();
$type = $curlResult->getContentType();
} else {
use Friendica\Core\Config\Factory\Config;
use Friendica\Model\Register;
use Friendica\Module\BaseAdmin;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPException\ServiceUnavailableException;
use Friendica\Util\DateTimeFormat;
private static function checkSelfHostMeta()
{
// 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();
}
}
use Friendica\Model;
use Friendica\Module\Response;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Protocol;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
$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);
use Friendica\Model\Contact;
use Friendica\Model\User;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\HTTPSignature;
use Friendica\Util\Profiler;
use Friendica\Core\Storage\Type\ExternalResource;
use Friendica\Core\Storage\Type\SystemResource;
use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\NotModifiedException;
use Friendica\Object\Image;
}
$mimetext = '';
if (!empty($url)) {
- $mime = ParseUrl::getContentType($url);
+ $mime = ParseUrl::getContentType($url, HttpClient::ACCEPT_IMAGE);
if (!empty($mime)) {
$mimetext = $mime[0] . '/' . $mime[1];
} else {
if (!empty($mimetext) && ($mime[0] != 'image') && ($mimetext != 'application/octet-stream')) {
Logger::info('Unexpected Content-Type', ['mime' => $mimetext, 'url' => $url]);
$mimetext = '';
+ } if (!empty($mimetext)) {
+ Logger::debug('Expected Content-Type', ['mime' => $mimetext, 'url' => $url]);
}
}
if (empty($mimetext)) {
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException\NotModifiedException;
use Friendica\Object\Image;
use Friendica\Util\HTTPSignature;
$request['url'] = str_replace(' ', '+', $request['url']);
// 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(), ['accept_content' => [HttpClient::ACCEPT_IMAGE], 'timeout' => 10]);
$img_str = $fetchResult->getBody();
if (!$fetchResult->isSuccess() || empty($img_str)) {
// stop.
}
+ Logger::debug('Got picture', ['Content-Type' => $fetchResult->getHeader('Content-Type'), 'uid' => local_user(), 'image' => $request['url']]);
+
$mime = Images::getMimeTypeByData($img_str);
$image = new Image($img_str, $mime);
const ACCEPT_JRD_JSON = 'application/jrd+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_MAGIC = 'application/magic-envelope+xml';
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';
Logger::info('Probing', ['host' => $host, 'ssl_url' => $ssl_url, 'url' => $url, 'callstack' => System::callstack(20)]);
$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);
if ($curlResult->isSuccess()) {
$xml = $curlResult->getBody();
}
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);
if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $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()) {
return false;
}
public static function pollZot($url, $data)
{
- $curlResult = DI::httpClient()->get($url);
+ // @todo Check if this endpoint might be queried via a POST
+ $curlResult = DI::httpClient()->get($url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
if ($curlResult->isTimeout()) {
return $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()) {
self::$istimeout = true;
return $data;
*/
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()) {
self::$istimeout = true;
return [];
$pubkey = substr($pubkey, 5);
}
} elseif (Strings::normaliseLink($pubkey) == 'http://') {
- $curlResult = DI::httpClient()->get($pubkey);
+ $curlResult = DI::httpClient()->get($pubkey, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
if ($curlResult->isTimeout()) {
self::$istimeout = true;
return $short ? false : [];
}
// 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()) {
self::$istimeout = true;
return [];
*/
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())) {
return [];
}
*/
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()) {
self::$istimeout = true;
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())) {
$noscrape = json_decode($curlResult->getBody(), true);
private static function updateFromFeed(array $data)
{
// 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()) {
return '';
}
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\Probe;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
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) {
Logger::info("Envelope was fetched.");
$x = self::verifyMagicEnvelope($envelope);
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
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())) {
return;
}
}
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()) {
$xml = $conversation_atom->getBody();
return;
}
- $curlResult = DI::httpClient()->get($self);
+ $curlResult = DI::httpClient()->get($self, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if (!$curlResult->isSuccess()) {
return;
}
$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())) {
return;
}
}
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()) {
Logger::info('Fetched XML for URI ' . $related_uri);
// Workaround for older GNU Social servers
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()) {
Logger::info('GNU Social workaround to fetch XML for URI ' . $related_uri);
// 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');
+ $curlResult = DI::httpClient()->get(str_replace('/notice/', '/api/statuses/show/', $related_guess) . '.atom', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_ATOM_XML]);
if ($curlResult->isSuccess()) {
Logger::info('GNU Social workaround 2 to fetch XML for URI ' . $related_uri);
use Friendica\Core\Logger;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\Probe;
use Friendica\Util\Crypto;
use Friendica\Util\Strings;
$ret[$x] = substr($ret[$x], 5);
}
} elseif (Strings::normaliseLink($ret[$x]) == 'http://') {
- $ret[$x] = DI::httpClient()->fetch($ret[$x]);
+ $ret[$x] = DI::httpClient()->fetch($ret[$x], 0, HttpClient::ACCEPT_DEFAULT);
}
}
}
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Model\User;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPException;
use Friendica\Util\PidFile;
$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()) {
return false;
use Friendica\Core\Logger;
use Friendica\DI;
use Friendica\Model\Photo;
+use Friendica\Network\HTTPClient\Client\HttpClient;
/**
* Image utilities
}
if (empty($img_str)) {
- $img_str = DI::httpClient()->fetch($url, 4);
+ $img_str = DI::httpClient()->fetch($url, 4, HttpClient::ACCEPT_IMAGE);
}
if (!$img_str) {
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
/**
* 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
*/
- 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
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()) {
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())) {
Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]);
return $siteinfo;
use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
/**
* Check the git repository VERSION file and save the version to the DB
Logger::info("Checking VERSION from: ".$checked_url);
// 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);
DI::config()->set('system', 'git_friendica_version', $gitversion);
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClient;
/**
* Sends updated profile data to the directory
Logger::info('Updating directory: ' . $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_DEFAULT);
}
return;
use Friendica\Core\Logger;
use Friendica\DI;
use Friendica\Model\Nodeinfo as ModelNodeInfo;
+use Friendica\Network\HTTPClient\Client\HttpClient;
class NodeInfo
{
// Now trying to register
$url = 'http://the-federation.info/register/' . DI::baseUrl()->getHostname();
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::info('end');
}
}
$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);
if ($curlResult->isTimeout()) {
use Friendica\Core\Logger;
use Friendica\DI;
use Friendica\Model\Contact;
+use Friendica\Network\HTTPClient\Client\HttpClient;
class PullDirectory
{
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)) {
Logger::info('Directory server return empty result.', ['directory' => $directory]);
return;
use Friendica\Core\Search;
use Friendica\DI;
use Friendica\Model\Contact;
+use Friendica\Network\HTTPClient\Client\HttpClient;
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);
if (!empty($j->results)) {
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\GServer;
+use Friendica\Network\HTTPClient\Client\HttpClient;
class UpdateServerDirectory
{
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)) {
Logger::info('Empty result', ['url' => $gserver['url']]);
return;
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)) {
Logger::info('Empty result', ['url' => $gserver['url']]);
return;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\GServer;
+use Friendica\Network\HTTPClient\Client\HttpClient;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Strings;
class UpdateServerPeers
*/
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())) {
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
return;