File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -1022,14 +1022,12 @@ public function setDefaultDecoder($mixed = 'json')
1022
1022
{
1023
1023
if ($ mixed === false ) {
1024
1024
$ this ->defaultDecoder = false ;
1025
+ } elseif ($ mixed === 'json ' ) {
1026
+ $ this ->defaultDecoder = '\Curl\Decoder::decodeJson ' ;
1027
+ } elseif ($ mixed === 'xml ' ) {
1028
+ $ this ->defaultDecoder = '\Curl\Decoder::decodeXml ' ;
1025
1029
} elseif (is_callable ($ mixed )) {
1026
1030
$ this ->defaultDecoder = $ mixed ;
1027
- } else {
1028
- if ($ mixed === 'json ' ) {
1029
- $ this ->defaultDecoder = '\Curl\Decoder::decodeJson ' ;
1030
- } elseif ($ mixed === 'xml ' ) {
1031
- $ this ->defaultDecoder = '\Curl\Decoder::decodeXml ' ;
1032
- }
1033
1031
}
1034
1032
}
1035
1033
@@ -2155,7 +2153,8 @@ private function parseResponse($response_headers, $raw_response)
2155
2153
}
2156
2154
}
2157
2155
2158
- if (isset ($ response_headers ['Content-Encoding ' ]) && $ response_headers ['Content-Encoding ' ] === 'gzip ' ) {
2156
+ if (isset ($ response_headers ['Content-Encoding ' ]) && $ response_headers ['Content-Encoding ' ] === 'gzip ' &&
2157
+ is_string ($ response )) {
2159
2158
// Use @ to suppress message "Warning gzdecode(): data error".
2160
2159
$ decoded_response = @gzdecode ($ response );
2161
2160
if ($ decoded_response !== false ) {
Original file line number Diff line number Diff line change @@ -4411,4 +4411,25 @@ public function testGzipDecodingFailureWithoutWarning()
4411
4411
$ this ->assertEquals ('gzip ' , $ test ->curl ->responseHeaders ['content-encoding ' ]);
4412
4412
$ this ->assertEquals ('<html><body>not gzip-encoded</body></html> ' , $ test ->curl ->response );
4413
4413
}
4414
+
4415
+ public function testGzipDecodingNonStringResponseWithoutError ()
4416
+ {
4417
+ $ test = new Test ();
4418
+ $ test ->curl ->setDefaultDecoder (function () {
4419
+ $ response = new \stdClass ();
4420
+ $ response ->{'abc ' } = 'foo ' ;
4421
+ $ response ->{'123 ' } = 'bar ' ;
4422
+ return $ response ;
4423
+ });
4424
+ $ test ->server ('json_response ' , 'POST ' , [
4425
+ 'headers ' => [
4426
+ 'content-type: text/html; charset=utf-8 ' ,
4427
+ 'content-encoding: gzip ' ,
4428
+ ],
4429
+ ]);
4430
+ $ this ->assertEquals ('text/html; charset=utf-8 ' , $ test ->curl ->responseHeaders ['content-type ' ]);
4431
+ $ this ->assertEquals ('gzip ' , $ test ->curl ->responseHeaders ['content-encoding ' ]);
4432
+ $ this ->assertEquals ('foo ' , $ test ->curl ->response ->{'abc ' });
4433
+ $ this ->assertEquals ('bar ' , $ test ->curl ->response ->{'123 ' });
4434
+ }
4414
4435
}
You can’t perform that action at this time.
0 commit comments