Format response header type notice as sentence

This commit is contained in:
Zach Borboa
2023-01-26 16:58:45 -08:00
parent f6ed305633
commit 99bd995288
2 changed files with 43 additions and 4 deletions
+4 -4
View File
@@ -1294,7 +1294,7 @@ class Curl extends BaseCurl
if ($request_headers_count === 0 && (
$this->getOpt(CURLOPT_VERBOSE) ||
$this->getOpt(CURLINFO_HEADER_OUT) !== true
!$this->getOpt(CURLINFO_HEADER_OUT)
)) {
echo
'Warning: Request headers (Curl::requestHeaders) are expected to be empty ' .
@@ -1327,11 +1327,11 @@ class Curl extends BaseCurl
}
if (!isset($this->responseHeaders['Content-Type'])) {
echo 'Response did not set a content type' . "\n";
echo 'Response did not set a content type.' . "\n";
} elseif (preg_match($this->jsonPattern, $this->responseHeaders['Content-Type'])) {
echo 'Response appears to be JSON' . "\n";
echo 'Response appears to be JSON.' . "\n";
} elseif (preg_match($this->xmlPattern, $this->responseHeaders['Content-Type'])) {
echo 'Response appears to be XML' . "\n";
echo 'Response appears to be XML.' . "\n";
}
if ($this->curlError) {
+39
View File
@@ -4301,6 +4301,45 @@ class CurlTest extends \PHPUnit\Framework\TestCase
}
}
public function testDiagnoseRequestHeadersEmptyWarning()
{
$expect = 'Warning: Request headers (Curl::requestHeaders) are expected to be empty';
$test_1 = new Test();
$test_1->curl->verbose();
$test_1->server('json_response', 'GET');
$test_1_output = $test_1->curl->diagnose(true);
$this->assertStringContainsString($expect, $test_1_output);
$test_2 = new Test();
$test_2->curl->setOpt(CURLOPT_VERBOSE, true);
$test_2->curl->setOpt(CURLINFO_HEADER_OUT, false);
$test_2->server('json_response', 'GET');
$test_2_output = $test_2->curl->diagnose(true);
$this->assertStringContainsString($expect, $test_2_output);
$test_3 = new Test();
$test_3->curl->setOpt(CURLOPT_VERBOSE, true);
$test_3->curl->setOpt(CURLINFO_HEADER_OUT, 0);
$test_3->server('json_response', 'GET');
$test_3_output = $test_3->curl->diagnose(true);
$this->assertStringContainsString($expect, $test_3_output);
$test_4 = new Test();
$test_4->curl->setOpt(CURLOPT_VERBOSE, 1);
$test_4->curl->setOpt(CURLINFO_HEADER_OUT, false);
$test_4->server('json_response', 'GET');
$test_4_output = $test_4->curl->diagnose(true);
$this->assertStringContainsString($expect, $test_4_output);
$test_5 = new Test();
$test_5->curl->setOpt(CURLOPT_VERBOSE, 1);
$test_5->curl->setOpt(CURLINFO_HEADER_OUT, 0);
$test_5->server('json_response', 'GET');
$test_5_output = $test_5->curl->diagnose(true);
$this->assertStringContainsString($expect, $test_5_output);
}
public function testStopRequest() {
$response_length_bytes = 1e6; // 1e6 = 1 megabyte