Skip to content

Commit

Permalink
Check available compression types of curl
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Brahmer <[email protected]>
  • Loading branch information
Grotax committed Aug 22, 2023
1 parent ca9e07b commit 4903d80
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/Config/FetcherConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,32 @@ public function __construct(IConfig $config)
return $this;
}

/**
* Checks for available encoding options
*
* @return String list of supported encoding types
*/
private function checkEncoding()
{
$supportedEncoding = [];

$curl_version = curl_version();

$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
$curl_version['features'] & constant($feature) ? $supportedEncoding = array_merge($supportedEncoding, $header) : null;

}
return implode(", ", $supportedEncoding);

}

/**
* Configure a guzzle client
*
Expand All @@ -106,7 +132,7 @@ public function getClient(): ClientInterface
'headers' => [
'User-Agent' => static::DEFAULT_USER_AGENT,
'Accept' => static::DEFAULT_ACCEPT,
'Accept-Encoding' => 'gzip, deflate',
'Accept-Encoding' => $this->checkEncoding()
],
];

Expand Down

0 comments on commit 4903d80

Please sign in to comment.