Skip to content

Commit

Permalink
Merge pull request #12 from car-api-team/check-for-content-encoding
Browse files Browse the repository at this point in the history
Check for content encoding
  • Loading branch information
carapidev authored Nov 30, 2024
2 parents da3faec + 23240fc commit 01a818d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/CarApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public function authenticate(): string
);
}

if (in_array('gzip', $this->config->encoding) && \extension_loaded('zlib')) {
$encoding = array_map(fn (string $str) => strtolower($str), $response->getHeader('Content-Encoding'));
if (in_array('gzip', $encoding)
&& in_array('gzip', $this->config->encoding)
&& \extension_loaded('zlib')
) {
$body = gzdecode($body);
if ($body === false) {
throw new CarApiException('Unable to decompress response. Maybe try without gzip.');
Expand Down Expand Up @@ -432,7 +436,11 @@ private function getDecoded(string $url, array $options = [], ?bool $associative
$response = $this->get($url, $options);
$body = (string) $response->getBody();

if (in_array('gzip', $this->config->encoding) && \extension_loaded('zlib')) {
$encoding = array_map(fn (string $str) => strtolower($str), $response->getHeader('Content-Encoding'));
if (in_array('gzip', $encoding)
&& in_array('gzip', $this->config->encoding)
&& \extension_loaded('zlib')
) {
$body = gzdecode($body);
if ($body === false) {
throw new CarApiException('Unable to decompress response. Maybe try without gzip.');
Expand Down

0 comments on commit 01a818d

Please sign in to comment.