Merge pull request #778 from zachborboa/master

Handle missing content-type response header in Curl::diagnose()
This commit is contained in:
Zach Borboa
2023-05-15 19:58:42 -07:00
committed by GitHub
3 changed files with 18 additions and 1 deletions
+2 -1
View File
@@ -1389,7 +1389,8 @@ class Curl extends BaseCurl
echo 'Response content length (calculated): ' . $response_calculated_length . "\n";
}
if (preg_match($this->jsonPattern, $this->responseHeaders['Content-Type'])) {
if (isset($this->responseHeaders['Content-Type']) &&
preg_match($this->jsonPattern, $this->responseHeaders['Content-Type'])) {
$parsed_response = json_decode($this->rawResponse, true);
if ($parsed_response !== null) {
$messages = [];
+12
View File
@@ -4363,6 +4363,18 @@ class PHPCurlClassTest extends \PHPUnit\Framework\TestCase
$this->assertStringContainsString($expect, $test_5_output);
}
public function testDiagnoseContentTypeMissing()
{
$test = new Test();
$test->server('json_response', 'POST', [
'remove-content-type-header' => '',
]);
$test_output = $test->curl->diagnose(true);
$this->assertFalse(isset($test->curl->responseHeaders['content-type']));
$this->assertStringContainsString('Response did not set a content type', $test_output);
}
public function testStopRequest()
{
$response_length_bytes = 1e6; // 1e6 = 1 megabyte
+4
View File
@@ -217,6 +217,10 @@ if ($test === 'http_basic_auth') {
]);
}
if (isset($_POST['remove-content-type-header'])) {
header_remove('Content-Type');
}
echo $body;
exit;
} elseif ($test === 'xml_response') {