From 82f8c14633719117b1be9c54c98f0df30595ba27 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 2 Apr 2022 21:16:21 +0200 Subject: [PATCH 1/4] Move ACCEPT constants to own "enum" class --- dwpost/dwpost.php | 3 ++- ijpost/ijpost.php | 3 ++- ljpost/ljpost.php | 3 ++- mailstream/mailstream.php | 3 ++- pumpio/pumpio.php | 3 ++- statusnet/statusnet.php | 3 ++- webdav_storage/src/WebDav.php | 15 ++++++++------- webdav_storage/src/WebDavConfig.php | 3 ++- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/dwpost/dwpost.php b/dwpost/dwpost.php index 286d8012..bab93dff 100644 --- a/dwpost/dwpost.php +++ b/dwpost/dwpost.php @@ -17,6 +17,7 @@ use Friendica\DI; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Util\DateTimeFormat; use Friendica\Util\XML; @@ -192,7 +193,7 @@ EOT; Logger::debug('dwpost: data: ' . $xml); 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 : ''); diff --git a/ijpost/ijpost.php b/ijpost/ijpost.php index 79cd75c8..832dff2c 100644 --- a/ijpost/ijpost.php +++ b/ijpost/ijpost.php @@ -16,6 +16,7 @@ use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Model\Tag; use Friendica\Model\User; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Util\DateTimeFormat; use Friendica\Util\XML; @@ -186,7 +187,7 @@ EOT; Logger::debug('ijpost: data: ' . $xml); 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 : ''); } diff --git a/ljpost/ljpost.php b/ljpost/ljpost.php index 073a977e..2fa5e782 100644 --- a/ljpost/ljpost.php +++ b/ljpost/ljpost.php @@ -17,6 +17,7 @@ use Friendica\DI; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Util\DateTimeFormat; use Friendica\Util\XML; @@ -206,7 +207,7 @@ EOT; Logger::debug('ljpost: data: ' . $xml); 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 : ''); } diff --git a/mailstream/mailstream.php b/mailstream/mailstream.php index 33959e1e..60d6412b 100644 --- a/mailstream/mailstream.php +++ b/mailstream/mailstream.php @@ -19,6 +19,7 @@ use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\User; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; @@ -207,7 +208,7 @@ function mailstream_do_images(&$item, &$attachments) continue; } $cookiejar = tempnam(System::getTempPath(), 'cookiejar-mailstream-'); - $curlResult = DI::httpClient()->fetchFull($url, 0, '', $cookiejar); + $curlResult = DI::httpClient()->fetchFull($url, HttpClientAccept::DEFAULT, 0, $cookiejar); $attachments[$url] = [ 'data' => $curlResult->getBody(), 'guid' => hash("crc32", $url), diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 62ad7712..1253d376 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -22,6 +22,7 @@ use Friendica\Model\Group; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\User; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Protocol\Activity; use Friendica\Protocol\ActivityNamespace; @@ -1487,7 +1488,7 @@ function pumpio_fetchallcomments(App $a, $uid, $id) function pumpio_reachable($url) { - return DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => 10])->isSuccess(); + return DI::httpClient()->get($url, HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => 10])->isSuccess(); } /* diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index b2582b86..6fc1469c 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -56,6 +56,7 @@ use Friendica\Model\Item; use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\User; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; use Friendica\Util\Strings; @@ -1367,7 +1368,7 @@ function statusnet_convertmsg(App $a, $body) } elseif ($oembed_data->type != "link") { $body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body); } else { - $img_str = DI::httpClient()->fetch($expanded_url, 4); + $img_str = DI::httpClient()->fetch($expanded_url, HttpClientAccept::DEFAULT, 4); $tempfile = tempnam(System::getTempPath(), "cache"); file_put_contents($tempfile, $img_str); diff --git a/webdav_storage/src/WebDav.php b/webdav_storage/src/WebDav.php index de9fc476..2e6b5b4e 100644 --- a/webdav_storage/src/WebDav.php +++ b/webdav_storage/src/WebDav.php @@ -6,6 +6,7 @@ use Exception; use Friendica\Core\Storage\Capability\ICanWriteToStorage; use Friendica\Core\Storage\Exception\ReferenceStorageException; use Friendica\Core\Storage\Exception\StorageException; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Util\Strings; @@ -85,7 +86,7 @@ class WebDav implements ICanWriteToStorage */ 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(), ]; - $response = $this->client->request('propfind', $uri, $opts); + $response = $this->client->request('propfind', $uri, HttpClientAccept::DEFAULT, $opts); $responseDoc = new \DOMDocument(); $responseDoc->loadXML($response->getBody()); @@ -133,7 +134,7 @@ class WebDav implements ICanWriteToStorage */ 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; } @@ -177,7 +178,7 @@ class WebDav implements ICanWriteToStorage foreach ($pathParts as $pathPart) { $checkUrl = $this->url . $partURL; 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->getReturnCode() == "404") { @@ -199,7 +200,7 @@ class WebDav implements ICanWriteToStorage { $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()) { throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference)); @@ -229,7 +230,7 @@ class WebDav implements ICanWriteToStorage 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; } @@ -241,7 +242,7 @@ class WebDav implements ICanWriteToStorage { $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()) { throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference)); diff --git a/webdav_storage/src/WebDavConfig.php b/webdav_storage/src/WebDavConfig.php index 2236e97a..4a0c3c67 100644 --- a/webdav_storage/src/WebDavConfig.php +++ b/webdav_storage/src/WebDavConfig.php @@ -5,6 +5,7 @@ namespace Friendica\Addon\webdav_storage\src; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; use Friendica\Core\Storage\Capability\ICanConfigureStorage; +use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; 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 [ 'url' => $this->l10n->t('url is either invalid or not reachable'), ]; -- 2.43.5 From 707e03635b6e1e3a32510758707dfd7ccd750d74 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 3 Apr 2022 19:33:08 +0200 Subject: [PATCH 2/4] Remove accept parameter for head/post again --- dwpost/dwpost.php | 3 +-- ijpost/ijpost.php | 3 +-- ljpost/ljpost.php | 3 +-- webdav_storage/src/WebDav.php | 4 ++-- webdav_storage/src/WebDavConfig.php | 3 +-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/dwpost/dwpost.php b/dwpost/dwpost.php index bab93dff..286d8012 100644 --- a/dwpost/dwpost.php +++ b/dwpost/dwpost.php @@ -17,7 +17,6 @@ use Friendica\DI; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Util\DateTimeFormat; use Friendica\Util\XML; @@ -193,7 +192,7 @@ EOT; Logger::debug('dwpost: data: ' . $xml); if ($dw_blog !== 'test') { - $x = DI::httpClient()->post($dw_blog, $xml, HttpClientAccept::DEFAULT, ['Content-Type' => 'text/xml'])->getBody(); + $x = DI::httpClient()->post($dw_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); } Logger::info('posted to dreamwidth: ' . ($x) ? $x : ''); diff --git a/ijpost/ijpost.php b/ijpost/ijpost.php index 832dff2c..79cd75c8 100644 --- a/ijpost/ijpost.php +++ b/ijpost/ijpost.php @@ -16,7 +16,6 @@ use Friendica\Core\Renderer; use Friendica\DI; use Friendica\Model\Tag; use Friendica\Model\User; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Util\DateTimeFormat; use Friendica\Util\XML; @@ -187,7 +186,7 @@ EOT; Logger::debug('ijpost: data: ' . $xml); if ($ij_blog !== 'test') { - $x = DI::httpClient()->post($ij_blog, $xml, HttpClientAccept::DEFAULT, ['Content-Type' => 'text/xml'])->getBody(); + $x = DI::httpClient()->post($ij_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); } Logger::info('posted to insanejournal: ' . $x ? $x : ''); } diff --git a/ljpost/ljpost.php b/ljpost/ljpost.php index 2fa5e782..073a977e 100644 --- a/ljpost/ljpost.php +++ b/ljpost/ljpost.php @@ -17,7 +17,6 @@ use Friendica\DI; use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Model\User; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Util\DateTimeFormat; use Friendica\Util\XML; @@ -207,7 +206,7 @@ EOT; Logger::debug('ljpost: data: ' . $xml); if ($lj_blog !== 'test') { - $x = DI::httpClient()->post($lj_blog, $xml, HttpClientAccept::DEFAULT, ['Content-Type' => 'text/xml'])->getBody(); + $x = DI::httpClient()->post($lj_blog, $xml, ['Content-Type' => 'text/xml'])->getBody(); } Logger::info('posted to livejournal: ' . ($x) ? $x : ''); } diff --git a/webdav_storage/src/WebDav.php b/webdav_storage/src/WebDav.php index 2e6b5b4e..1a31a4c2 100644 --- a/webdav_storage/src/WebDav.php +++ b/webdav_storage/src/WebDav.php @@ -86,7 +86,7 @@ class WebDav implements ICanWriteToStorage */ protected function exists(string $uri): bool { - return $this->client->head($uri, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions])->getReturnCode() == 200; + return $this->client->head($uri, [HttpClientOptions::AUTH => $this->authOptions])->getReturnCode() == 200; } /** @@ -178,7 +178,7 @@ class WebDav implements ICanWriteToStorage foreach ($pathParts as $pathPart) { $checkUrl = $this->url . $partURL; if (!empty($partURL) && !$this->hasItems($checkUrl)) { - $response = $this->client->request('delete', $checkUrl, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions]); + $response = $this->client->request('delete', $checkUrl, [HttpClientOptions::AUTH => $this->authOptions]); if (!$response->isSuccess()) { if ($response->getReturnCode() == "404") { diff --git a/webdav_storage/src/WebDavConfig.php b/webdav_storage/src/WebDavConfig.php index 4a0c3c67..2236e97a 100644 --- a/webdav_storage/src/WebDavConfig.php +++ b/webdav_storage/src/WebDavConfig.php @@ -5,7 +5,6 @@ namespace Friendica\Addon\webdav_storage\src; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; use Friendica\Core\Storage\Capability\ICanConfigureStorage; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; @@ -139,7 +138,7 @@ class WebDavConfig implements ICanConfigureStorage ]; } - if (!$this->client->head($url, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $options])->isSuccess()) { + if (!$this->client->head($url, [HttpClientOptions::AUTH => $options])->isSuccess()) { return [ 'url' => $this->l10n->t('url is either invalid or not reachable'), ]; -- 2.43.5 From 46221882c373dc9c8efb610102f4b825c1067ef8 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 3 Apr 2022 19:35:39 +0200 Subject: [PATCH 3/4] Remove accept parameter for request again --- webdav_storage/src/WebDav.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/webdav_storage/src/WebDav.php b/webdav_storage/src/WebDav.php index 1a31a4c2..a5ee5161 100644 --- a/webdav_storage/src/WebDav.php +++ b/webdav_storage/src/WebDav.php @@ -111,7 +111,7 @@ class WebDav implements ICanWriteToStorage HttpClientOptions::BODY => $dom->saveXML(), ]; - $response = $this->client->request('propfind', $uri, HttpClientAccept::DEFAULT, $opts); + $response = $this->client->request('propfind', $uri, $opts); $responseDoc = new \DOMDocument(); $responseDoc->loadXML($response->getBody()); @@ -134,7 +134,7 @@ class WebDav implements ICanWriteToStorage */ protected function mkcol(string $uri): bool { - return $this->client->request('mkcol', $uri, HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions]) + return $this->client->request('mkcol', $uri, [HttpClientOptions::AUTH => $this->authOptions]) ->getReturnCode() == 200; } @@ -200,7 +200,7 @@ class WebDav implements ICanWriteToStorage { $file = $this->pathForRef($reference); - $response = $this->client->request('get', $this->url . '/' . $file[0], HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions]); + $response = $this->client->request('get', $this->url . '/' . $file[0], [HttpClientOptions::AUTH => $this->authOptions]); if (!$response->isSuccess()) { throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference)); @@ -230,7 +230,7 @@ class WebDav implements ICanWriteToStorage HttpClientOptions::AUTH => $this->authOptions, ]; - $this->client->request('put', $this->url . '/' . $file[0], HttpClientAccept::DEFAULT, $opts); + $this->client->request('put', $this->url . '/' . $file[0], $opts); return $reference; } @@ -242,7 +242,7 @@ class WebDav implements ICanWriteToStorage { $file = $this->pathForRef($reference); - $response = $this->client->request('delete', $this->url . '/' . $file[0], HttpClientAccept::DEFAULT, [HttpClientOptions::AUTH => $this->authOptions]); + $response = $this->client->request('delete', $this->url . '/' . $file[0], [HttpClientOptions::AUTH => $this->authOptions]); if (!$response->isSuccess()) { throw new ReferenceStorageException(sprintf('Invalid reference %s', $reference)); -- 2.43.5 From bfc45428817b3b6f9a4d2f023b780ce89c270b90 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 8 Apr 2022 20:06:45 +0200 Subject: [PATCH 4/4] Remove redundant header --- webdav_storage/src/WebDav.php | 1 - 1 file changed, 1 deletion(-) diff --git a/webdav_storage/src/WebDav.php b/webdav_storage/src/WebDav.php index a5ee5161..de9fc476 100644 --- a/webdav_storage/src/WebDav.php +++ b/webdav_storage/src/WebDav.php @@ -6,7 +6,6 @@ use Exception; use Friendica\Core\Storage\Capability\ICanWriteToStorage; use Friendica\Core\Storage\Exception\ReferenceStorageException; use Friendica\Core\Storage\Exception\StorageException; -use Friendica\Network\HTTPClient\Client\HttpClientAccept; use Friendica\Network\HTTPClient\Client\HttpClientOptions; use Friendica\Network\HTTPClient\Capability\ICanSendHttpRequests; use Friendica\Util\Strings; -- 2.43.5