diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 9ef9fd6..037da9d 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -2155,7 +2155,8 @@ class Curl } } - if (isset($response_headers['Content-Encoding']) && $response_headers['Content-Encoding'] === 'gzip') { + if (isset($response_headers['Content-Encoding']) && $response_headers['Content-Encoding'] === 'gzip' && + is_string($response)) { // Use @ to suppress message "Warning gzdecode(): data error". $decoded_response = @gzdecode($response); if ($decoded_response !== false) { diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 3622f61..e07708c 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -4411,4 +4411,25 @@ class CurlTest extends \PHPUnit\Framework\TestCase $this->assertEquals('gzip', $test->curl->responseHeaders['content-encoding']); $this->assertEquals('not gzip-encoded', $test->curl->response); } + + public function testGzipDecodingNonStringResponseWithoutError() + { + $test = new Test(); + $test->curl->setDefaultDecoder(function () { + $response = new \stdClass(); + $response->{'abc'} = 'foo'; + $response->{'123'} = 'bar'; + return $response; + }); + $test->server('json_response', 'POST', [ + 'headers' => [ + 'content-type: text/html; charset=utf-8', + 'content-encoding: gzip', + ], + ]); + $this->assertEquals('text/html; charset=utf-8', $test->curl->responseHeaders['content-type']); + $this->assertEquals('gzip', $test->curl->responseHeaders['content-encoding']); + $this->assertEquals('foo', $test->curl->response->{'abc'}); + $this->assertEquals('bar', $test->curl->response->{'123'}); + } }