mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Merge pull request #778 from zachborboa/master
Handle missing content-type response header in Curl::diagnose()
This commit is contained in:
+2
-1
@@ -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 = [];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user