mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-29 19:54:49 +00:00
Merge pull request #757 from zachborboa/master
Fix Curl::diagnose() request type output for POST requests
This commit is contained in:
+17
-13
@@ -1529,7 +1529,23 @@ class Curl
|
||||
if ($this->attempts === 0) {
|
||||
echo 'No HTTP requests have been made.' . "\n";
|
||||
} else {
|
||||
$request_method = $this->getOpt(CURLOPT_CUSTOMREQUEST);
|
||||
$request_types = array(
|
||||
'DELETE' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'DELETE',
|
||||
'GET' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'GET' || $this->getOpt(CURLOPT_HTTPGET),
|
||||
'HEAD' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'HEAD',
|
||||
'OPTIONS' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'OPTIONS',
|
||||
'PATCH' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'PATCH',
|
||||
'POST' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'POST' || $this->getOpt(CURLOPT_POST),
|
||||
'PUT' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'PUT',
|
||||
'SEARCH' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'SEARCH',
|
||||
);
|
||||
$request_method = '';
|
||||
foreach ($request_types as $http_method_name => $http_method_used) {
|
||||
if ($http_method_used) {
|
||||
$request_method = $http_method_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$request_url = $this->getOpt(CURLOPT_URL);
|
||||
$request_options_count = count($this->options);
|
||||
$request_headers_count = count($this->requestHeaders);
|
||||
@@ -1598,18 +1614,6 @@ class Curl
|
||||
$allowed_request_types = array_map(function ($v) {
|
||||
return trim($v);
|
||||
}, explode(',', strtoupper($this->responseHeaders['allow'])));
|
||||
|
||||
$request_types = array(
|
||||
'DELETE' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'DELETE',
|
||||
'GET' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'GET' || $this->getOpt(CURLOPT_HTTPGET),
|
||||
'HEAD' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'HEAD',
|
||||
'OPTIONS' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'OPTIONS',
|
||||
'PATCH' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'PATCH',
|
||||
'POST' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'POST' || $this->getOpt(CURLOPT_POST),
|
||||
'PUT' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'PUT',
|
||||
'SEARCH' => $this->getOpt(CURLOPT_CUSTOMREQUEST) === 'SEARCH',
|
||||
);
|
||||
|
||||
foreach ($request_types as $http_method_name => $http_method_used) {
|
||||
if ($http_method_used && !in_array($http_method_name, $allowed_request_types, true)) {
|
||||
echo
|
||||
|
||||
@@ -4081,7 +4081,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals(3, $curl->getOpt(CURLOPT_MAXREDIRS));
|
||||
}
|
||||
|
||||
public function testDiagnose()
|
||||
public function testDiagnoseOutputGet()
|
||||
{
|
||||
// Test diagnose() with default parameters.
|
||||
$test_1 = new Test();
|
||||
@@ -4122,6 +4122,28 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testDiagnoseOutputPost()
|
||||
{
|
||||
$test = new Test();
|
||||
$test->server('error_message', 'POST');
|
||||
$test_output = $test->curl->diagnose(true);
|
||||
|
||||
foreach ([
|
||||
'--- Begin PHP Curl Class diagnostic output ---',
|
||||
'PHP Curl Class version: ' . Curl::VERSION,
|
||||
'PHP version: ' . PHP_VERSION,
|
||||
'CURLOPT_POST: true',
|
||||
'Sent an HTTP POST request ',
|
||||
'Request contained no body.',
|
||||
'Received an HTTP status code of 401.',
|
||||
'Received an HTTP 401 error response with message "HTTP/1.1 401 Unauthorized".',
|
||||
'Received an empty response body (response="").',
|
||||
'--- End PHP Curl Class diagnostic output ---',
|
||||
] as $expected_string) {
|
||||
$this->assertStringContainsString($expected_string, $test_output);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDiagnoseAllowHeader()
|
||||
{
|
||||
$tests = [
|
||||
|
||||
Reference in New Issue
Block a user