summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBenjamin Brahmer <info@b-brahmer.de>2023-08-25 09:37:29 +0200
committerGitHub <noreply@github.com>2023-08-25 09:37:29 +0200
commitb99320dd4aa9c5c732d331bd54d65e8010c4662d (patch)
tree83b50d3fe312224acfc1efed52187d47db3eedf3 /lib
parentcaf30017730cd610d4d02d1f3622a1ecf1b560ce (diff)
Check available compression types of curl (#2328)
Check an use available compression types of curl use compression when downloading feed logo Co-authored-by: Sean Molenaar <SMillerDev@users.noreply.github.com> Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Config/FetcherConfig.php25
-rwxr-xr-xlib/Fetcher/FeedFetcher.php12
2 files changed, 34 insertions, 3 deletions
diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php
index 797dae49e..702fccdf1 100644
--- a/lib/Config/FetcherConfig.php
+++ b/lib/Config/FetcherConfig.php
@@ -95,6 +95,29 @@ class FetcherConfig
}
/**
+ * Checks for available encoding options
+ *
+ * @return String list of supported encoding types
+ */
+ public function checkEncoding()
+ {
+ $supportedEncoding = [];
+
+ // check curl features
+ $curl_features = curl_version()["features"];
+
+ $bitfields = array('CURL_VERSION_LIBZ' => ['gzip', 'deflate'], 'CURL_VERSION_BROTLI' => ['br']);
+
+ foreach ($bitfields as $feature => $header) {
+ // checking available features via the 'features' bitmask and adding available types to the list
+ if (defined($feature) && $curl_features & constant($feature)) {
+ $supportedEncoding = array_merge($supportedEncoding, $header);
+ }
+ }
+ return implode(", ", $supportedEncoding);
+ }
+
+ /**
* Configure a guzzle client
*
* @return ClientInterface Client to guzzle.
@@ -106,7 +129,7 @@ class FetcherConfig
'headers' => [
'User-Agent' => static::DEFAULT_USER_AGENT,
'Accept' => static::DEFAULT_ACCEPT,
- 'Accept-Encoding' => 'gzip, deflate',
+ 'Accept-Encoding' => $this->checkEncoding()
],
];
diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php
index 9fdee1d97..33fb2a508 100755
--- a/lib/Fetcher/FeedFetcher.php
+++ b/lib/Fetcher/FeedFetcher.php
@@ -73,6 +73,11 @@ class FeedFetcher implements IFeedFetcher
*/
private $logger;
+ /**
+ * @var FetcherConfig
+ */
+ private $fetcherConfig;
+
public function __construct(
FeedIo $fetcher,
Favicon $favicon,
@@ -80,7 +85,8 @@ class FeedFetcher implements IFeedFetcher
IL10N $l10n,
ITempManager $ITempManager,
Time $time,
- LoggerInterface $logger
+ LoggerInterface $logger,
+ FetcherConfig $fetcherConfig
) {
$this->reader = $fetcher;
$this->faviconFactory = $favicon;
@@ -89,6 +95,7 @@ class FeedFetcher implements IFeedFetcher
$this->ITempManager = $ITempManager;
$this->time = $time;
$this->logger = $logger;
+ $this->fetcherConfig = $fetcherConfig;
}
@@ -409,7 +416,8 @@ class FeedFetcher implements IFeedFetcher
'headers' => [
'User-Agent' => FetcherConfig::DEFAULT_USER_AGENT,
'Accept' => 'image/*',
- 'If-Modified-Since' => date(DateTime::RFC7231, $last_modified)
+ 'If-Modified-Since' => date(DateTime::RFC7231, $last_modified),
+ 'Accept-Encoding' => $this->fetcherConfig->checkEncoding()
]
]
);