Merge pull request #748 from zachborboa/master

Disable warning when gzip-decoding response errors
This commit is contained in:
Zach Borboa
2022-12-10 11:44:25 -08:00
committed by GitHub
3 changed files with 42 additions and 14 deletions
+2 -1
View File
@@ -2156,7 +2156,8 @@ class Curl
}
if (isset($response_headers['Content-Encoding']) && $response_headers['Content-Encoding'] === 'gzip') {
$decoded_response = gzdecode($response);
// Use @ to suppress message "Warning gzdecode(): data error".
$decoded_response = @gzdecode($response);
if ($decoded_response !== false) {
$response = $decoded_response;
}
+17
View File
@@ -4396,4 +4396,21 @@ class CurlTest extends \PHPUnit\Framework\TestCase
]);
$this->assertEquals('hello', $test->curl->response);
}
public function testGzipDecodingFailureWithoutWarning()
{
$test = new Test();
$test->server('json_response', 'POST', [
'keys' => [
'content-type',
'content-encoding',
],
'values' => [
'text/html; charset=utf-8',
'gzip',
],
'body' => '<html><body>not gzip-encoded</body></html>',
]);
$this->assertEquals('<html><body>not gzip-encoded</body></html>', $test->curl->response);
}
}
+23 -13
View File
@@ -181,20 +181,31 @@ if ($test === 'http_basic_auth') {
echo 'OK';
exit;
} elseif ($test === 'json_response') {
if (isset($_POST['key'])) {
$key = $_POST['key'];
} elseif (isset($_GET['key'])) {
$key = $_GET['key'];
if (isset($_POST['keys']) && isset($_POST['values'])) {
foreach ($_POST['keys'] as $index => $key) {
if (isset($_POST['values'][$index])) {
$value = $_POST['values'][$index];
header($key . ': ' . $value);
}
}
} else {
$key = 'Content-Type';
}
if (isset($_POST['key'])) {
$key = $_POST['key'];
} elseif (isset($_GET['key'])) {
$key = $_GET['key'];
} else {
$key = 'Content-Type';
}
if (isset($_POST['value'])) {
$value = $_POST['value'];
} elseif (isset($_GET['value'])) {
$value = $_GET['value'];
} else {
$value = 'application/json';
if (isset($_POST['value'])) {
$value = $_POST['value'];
} elseif (isset($_GET['value'])) {
$value = $_GET['value'];
} else {
$value = 'application/json';
}
header($key . ': ' . $value);
}
if (isset($_POST['body'])) {
@@ -211,7 +222,6 @@ if ($test === 'http_basic_auth') {
]);
}
header($key . ': ' . $value);
echo $body;
exit;
} elseif ($test === 'xml_response') {