Introduce "accept_header" as specific argument to the http client

This commit is contained in:
Philipp 2022-04-02 21:16:22 +02:00
parent 73c3b21665
commit e299fc67c8
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
35 changed files with 150 additions and 150 deletions

View file

@ -55,7 +55,7 @@ class CheckVersion
Logger::info("Checking VERSION from: ".$checked_url);
// fetch the VERSION file
$gitversion = DBA::escape(trim(DI::httpClient()->fetch($checked_url, 0, HttpClientAccept::TEXT)));
$gitversion = DBA::escape(trim(DI::httpClient()->fetch($checked_url, HttpClientAccept::TEXT)));
Logger::notice("Upstream VERSION is: ".$gitversion);
DI::config()->set('system', 'git_friendica_version', $gitversion);

View file

@ -54,7 +54,7 @@ class Directory
Logger::info('Updating directory: ' . $arr['url']);
if (strlen($arr['url'])) {
DI::httpClient()->fetch($dir . '?url=' . bin2hex($arr['url']), 0, HttpClientAccept::HTML);
DI::httpClient()->fetch($dir . '?url=' . bin2hex($arr['url']), HttpClientAccept::HTML);
}
return;

View file

@ -35,7 +35,7 @@ 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, 0, HttpClientAccept::HTML);
$ret = DI::httpClient()->fetch($url, HttpClientAccept::HTML);
Logger::debug('Check registering answer', ['answer' => $ret]);
Logger::info('end');
}

View file

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

View file

@ -25,6 +25,7 @@ use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\PushSubscriber;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Protocol\OStatus;
class PubSubPublish
@ -68,7 +69,7 @@ class PubSubPublish
Logger::debug('POST', ['headers' => $headers, 'params' => $params]);
$postResult = DI::httpClient()->post($subscriber['callback_url'], $params, $headers);
$postResult = DI::httpClient()->post($subscriber['callback_url'], $params, HttpClientAccept::DEFAULT, $headers);
$ret = $postResult->getReturnCode();
if ($ret >= 200 && $ret <= 299) {

View file

@ -48,7 +48,7 @@ class PullDirectory
Logger::info('Synchronization started.', ['now' => $now, 'directory' => $directory]);
$result = DI::httpClient()->fetch($directory . '/sync/pull/since/' . $now, 0, HttpClientAccept::JSON);
$result = DI::httpClient()->fetch($directory . '/sync/pull/since/' . $now, HttpClientAccept::JSON);
if (empty($result)) {
Logger::info('Directory server return empty result.', ['directory' => $directory]);
return;

View file

@ -47,7 +47,7 @@ class SearchDirectory
}
}
$x = DI::httpClient()->fetch(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search), 0, HttpClientAccept::JSON);
$x = DI::httpClient()->fetch(Search::getGlobalDirectory() . '/lsearch?p=1&n=500&search=' . urlencode($search), HttpClientAccept::JSON);
$j = json_decode($x);
if (!empty($j->results)) {

View file

@ -45,7 +45,7 @@ class UpdateServerDirectory
private static function discoverPoCo(array $gserver)
{
$result = DI::httpClient()->fetch($gserver['poco'] . '?fields=urls', 0, HttpClientAccept::JSON);
$result = DI::httpClient()->fetch($gserver['poco'] . '?fields=urls', HttpClientAccept::JSON);
if (empty($result)) {
Logger::info('Empty result', ['url' => $gserver['url']]);
return;
@ -78,7 +78,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', 0, HttpClientAccept::JSON);
$result = DI::httpClient()->fetch($gserver['url'] . '/api/v1/directory?order=new&local=true&limit=200&offset=0', HttpClientAccept::JSON);
if (empty($result)) {
Logger::info('Empty result', ['url' => $gserver['url']]);
return;

View file

@ -26,7 +26,6 @@ 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\Util\Strings;
class UpdateServerPeers
@ -37,7 +36,7 @@ class UpdateServerPeers
*/
public static function execute(string $url)
{
$ret = DI::httpClient()->get($url . '/api/v1/instance/peers', [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON]);
$ret = DI::httpClient()->get($url . '/api/v1/instance/peers', HttpClientAccept::JSON);
if (!$ret->isSuccess() || empty($ret->getBody())) {
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
return;