mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-22 02:50:52 +00:00
Display request options in Curl::diagnose() output
Request options are now displayed when Curl::diagnose() is called and a deferred constant curlOptionCodeConstants has been added.
This commit is contained in:
@@ -99,6 +99,7 @@ class Curl
|
||||
private static $deferredProperties = [
|
||||
'curlErrorCodeConstant',
|
||||
'curlErrorCodeConstants',
|
||||
'curlOptionCodeConstants',
|
||||
'effectiveUrl',
|
||||
'rfc2616',
|
||||
'rfc6265',
|
||||
@@ -1517,6 +1518,7 @@ class Curl
|
||||
} else {
|
||||
$request_method = $this->getOpt(CURLOPT_CUSTOMREQUEST);
|
||||
$request_url = $this->getOpt(CURLOPT_URL);
|
||||
$request_options_count = count($this->options);
|
||||
$request_headers_count = count($this->requestHeaders);
|
||||
$request_body_empty = empty($this->getOpt(CURLOPT_POSTFIELDS));
|
||||
$response_header_length = isset($this->responseHeaders['Content-Length']) ?
|
||||
@@ -1525,6 +1527,36 @@ class Curl
|
||||
strlen($this->rawResponse) : '(' . var_export($this->rawResponse, true) . ')';
|
||||
$response_headers_count = count($this->responseHeaders);
|
||||
|
||||
echo
|
||||
'Request contained ' . $request_options_count . ' ' . (
|
||||
$request_options_count === 1 ? 'option:' : 'options:'
|
||||
) . "\n";
|
||||
if ($request_options_count) {
|
||||
$i = 1;
|
||||
foreach ($this->options as $option => $value) {
|
||||
echo ' ' . $i . ' ';
|
||||
if (isset($this->curlOptionCodeConstants[$option])) {
|
||||
echo $this->curlOptionCodeConstants[$option] . ':';
|
||||
} else {
|
||||
echo $option . ':';
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
echo ' ' . $value . "\n";
|
||||
} elseif (is_int($value)) {
|
||||
echo ' ' . $value . "\n";
|
||||
} elseif (is_bool($value)) {
|
||||
echo ' ' . ($value ? 'true' : 'false') . "\n";
|
||||
} elseif (is_callable($value)) {
|
||||
echo ' (callable)' . "\n";
|
||||
} else {
|
||||
echo ' ' . gettype($value) . ':' . "\n";
|
||||
var_dump($value);
|
||||
}
|
||||
$i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
echo
|
||||
'Sent an HTTP ' . $request_method . ' request to "' . $request_url . '".' . "\n" .
|
||||
'Request contained ' . $request_headers_count . ' ' . (
|
||||
@@ -1889,6 +1921,25 @@ class Curl
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Curl Option Code Constants
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _get_curlOptionCodeConstants()
|
||||
{
|
||||
$constants = get_defined_constants(true);
|
||||
$filtered_array = array_filter(
|
||||
$constants['curl'],
|
||||
function ($key) {
|
||||
return strpos($key, 'CURLOPT_') !== false;
|
||||
},
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
$curl_const_by_code = array_flip($filtered_array);
|
||||
return $curl_const_by_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Effective Url
|
||||
*
|
||||
|
||||
@@ -4108,6 +4108,7 @@ class CurlTest extends \PHPUnit\Framework\TestCase
|
||||
'--- Begin PHP Curl Class diagnostic output ---',
|
||||
'PHP Curl Class version: ' . Curl::VERSION,
|
||||
'PHP version: ' . PHP_VERSION,
|
||||
'CURLOPT_HTTPGET: true',
|
||||
'Sent an HTTP GET request ',
|
||||
'Request contained no body.',
|
||||
'Received an HTTP status code of 401.',
|
||||
|
||||
Reference in New Issue
Block a user