Move ACCEPT constants to own "enum" class

This commit is contained in:
Philipp 2022-04-02 21:16:21 +02:00
parent aed0b53925
commit 82f8c14633
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
8 changed files with 22 additions and 14 deletions

View file

@ -17,6 +17,7 @@ use Friendica\DI;
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\HttpClientAccept;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -192,7 +193,7 @@ EOT;
Logger::debug('dwpost: data: ' . $xml); Logger::debug('dwpost: data: ' . $xml);
if ($dw_blog !== 'test') { if ($dw_blog !== 'test') {
$x = DI::httpClient()->post($dw_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); $x = DI::httpClient()->post($dw_blog, $xml, HttpClientAccept::DEFAULT, ['Content-Type' => 'text/xml'])->getBody();
} }
Logger::info('posted to dreamwidth: ' . ($x) ? $x : ''); Logger::info('posted to dreamwidth: ' . ($x) ? $x : '');

View file

@ -16,6 +16,7 @@ use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Tag; use Friendica\Model\Tag;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -186,7 +187,7 @@ EOT;
Logger::debug('ijpost: data: ' . $xml); Logger::debug('ijpost: data: ' . $xml);
if ($ij_blog !== 'test') { if ($ij_blog !== 'test') {
$x = DI::httpClient()->post($ij_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); $x = DI::httpClient()->post($ij_blog, $xml, HttpClientAccept::DEFAULT, ['Content-Type' => 'text/xml'])->getBody();
} }
Logger::info('posted to insanejournal: ' . $x ? $x : ''); Logger::info('posted to insanejournal: ' . $x ? $x : '');
} }

View file

@ -17,6 +17,7 @@ use Friendica\DI;
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\HttpClientAccept;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -206,7 +207,7 @@ EOT;
Logger::debug('ljpost: data: ' . $xml); Logger::debug('ljpost: data: ' . $xml);
if ($lj_blog !== 'test') { if ($lj_blog !== 'test') {
$x = DI::httpClient()->post($lj_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); $x = DI::httpClient()->post($lj_blog, $xml, HttpClientAccept::DEFAULT, ['Content-Type' => 'text/xml'])->getBody();
} }
Logger::info('posted to livejournal: ' . ($x) ? $x : ''); Logger::info('posted to livejournal: ' . ($x) ? $x : '');
} }

View file

@ -19,6 +19,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
@ -207,7 +208,7 @@ function mailstream_do_images(&$item, &$attachments)
continue; continue;
} }
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-mailstream-'); $cookiejar = tempnam(System::getTempPath(), 'cookiejar-mailstream-');
$curlResult = DI::httpClient()->fetchFull($url, 0, '', $cookiejar); $curlResult = DI::httpClient()->fetchFull($url, HttpClientAccept::DEFAULT, 0, $cookiejar);
$attachments[$url] = [ $attachments[$url] = [
'data' => $curlResult->getBody(), 'data' => $curlResult->getBody(),
'guid' => hash("crc32", $url), 'guid' => hash("crc32", $url),

View file

@ -22,6 +22,7 @@ use Friendica\Model\Group;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityNamespace;
@ -1487,7 +1488,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id)
function pumpio_reachable($url) function pumpio_reachable($url)
{ {
return DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => 10])->isSuccess(); return DI::httpClient()->get($url, HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => 10])->isSuccess();
} }
/* /*

View file

@ -56,6 +56,7 @@ use Friendica\Model\Item;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Protocol\Activity; use Friendica\Protocol\Activity;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -1367,7 +1368,7 @@ function statusnet_convertmsg(App $a, $body)
} elseif ($oembed_data->type != "link") { } elseif ($oembed_data->type != "link") {
$body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); $body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
} else { } else {
$img_str = DI::httpClient()->fetch($expanded_url, 4); $img_str = DI::httpClient()->fetch($expanded_url, HttpClientAccept::DEFAULT, 4);
$tempfile = tempnam(System::getTempPath(), "cache"); $tempfile = tempnam(System::getTempPath(), "cache");
file_put_contents($tempfile, $img_str); file_put_contents($tempfile, $img_str);

View file

@ -6,6 +6,7 @@ use Exception;
use Friendica\Core\Storage\Capability\ICanWriteToStorage; use Friendica\Core\Storage\Capability\ICanWriteToStorage;
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\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
use Friendica\Util\Strings; use Friendica\Util\Strings;
@ -85,7 +86,7 @@ class WebDav implements ICanWriteToStorage
*/ */
protected function exists(string $uri): bool protected function exists(string $uri): bool
{ {
return $this->client->head($uri, [HttpClientOptions::AUTH => $this->authOptions])->getReturnCode() == 200; return $this->client->head($uri, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions])->getReturnCode() == 200;
} }
/** /**
@ -110,7 +111,7 @@ class WebDav implements ICanWriteToStorage
HttpClientOptions::BODY => $dom->saveXML(), HttpClientOptions::BODY => $dom->saveXML(),
]; ];
$response = $this->client->request('propfind', $uri, $opts); $response = $this->client->request('propfind', $uri, HttpClientAccept::DEFAULT, $opts);
$responseDoc = new \DOMDocument(); $responseDoc = new \DOMDocument();
$responseDoc->loadXML($response->getBody()); $responseDoc->loadXML($response->getBody());
@ -133,7 +134,7 @@ class WebDav implements ICanWriteToStorage
*/ */
protected function mkcol(string $uri): bool protected function mkcol(string $uri): bool
{ {
return $this->client->request('mkcol', $uri, [HttpClientOptions::AUTH => $this->authOptions]) return $this->client->request('mkcol', $uri, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions])
->getReturnCode() == 200; ->getReturnCode() == 200;
} }
@ -177,7 +178,7 @@ class WebDav implements ICanWriteToStorage
foreach ($pathParts as $pathPart) { foreach ($pathParts as $pathPart) {
$checkUrl = $this->url . $partURL; $checkUrl = $this->url . $partURL;
if (!empty($partURL) && !$this->hasItems($checkUrl)) { if (!empty($partURL) && !$this->hasItems($checkUrl)) {
$response = $this->client->request('delete', $checkUrl, [HttpClientOptions::AUTH => $this->authOptions]); $response = $this->client->request('delete', $checkUrl, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions]);
if (!$response->isSuccess()) { if (!$response->isSuccess()) {
if ($response->getReturnCode() == "404") { if ($response->getReturnCode() == "404") {
@ -199,7 +200,7 @@ class WebDav implements ICanWriteToStorage
{ {
$file = $this->pathForRef($reference); $file = $this->pathForRef($reference);
$response = $this->client->request('get', $this->url . '/' . $file[0], [HttpClientOptions::AUTH => $this->authOptions]); $response = $this->client->request('get', $this->url . '/' . $file[0], HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions]);
if (!$response->isSuccess()) { if (!$response->isSuccess()) {
throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference)); throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference));
@ -229,7 +230,7 @@ class WebDav implements ICanWriteToStorage
HttpClientOptions::AUTH => $this->authOptions, HttpClientOptions::AUTH => $this->authOptions,
]; ];
$this->client->request('put', $this->url . '/' . $file[0], $opts); $this->client->request('put', $this->url . '/' . $file[0], HttpClientAccept::DEFAULT, $opts);
return $reference; return $reference;
} }
@ -241,7 +242,7 @@ class WebDav implements ICanWriteToStorage
{ {
$file = $this->pathForRef($reference); $file = $this->pathForRef($reference);
$response = $this->client->request('delete', $this->url . '/' . $file[0], [HttpClientOptions::AUTH => $this->authOptions]); $response = $this->client->request('delete', $this->url . '/' . $file[0], HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions]);
if (!$response->isSuccess()) { if (!$response->isSuccess()) {
throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference)); throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference));

View file

@ -5,6 +5,7 @@ namespace Friendica\Addon\webdav_storage\src;
use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Storage\Capability\ICanConfigureStorage; use Friendica\Core\Storage\Capability\ICanConfigureStorage;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests;
@ -138,7 +139,7 @@ class WebDavConfig implements ICanConfigureStorage
]; ];
} }
if (!$this->client->head($url, [HttpClientOptions::AUTH => $options])->isSuccess()) { if (!$this->client->head($url, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $options])->isSuccess()) {
return [ return [
'url' => $this->l10n->t('url is either invalid or not reachable'), 'url' => $this->l10n->t('url is either invalid or not reachable'),
]; ];