mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-25 10:09:06 +00:00
Separate curl error and curl error code from http error and http error code
This commit is contained in:
+8
-3
@@ -83,9 +83,13 @@ class Curl {
|
||||
|
||||
function _exec() {
|
||||
$this->response = curl_exec($this->curl);
|
||||
$this->error_code = curl_errno($this->curl);
|
||||
$this->error_message = curl_error($this->curl);
|
||||
$this->error = !($this->error_code === 0);
|
||||
$this->curl_error_code = curl_errno($this->curl);
|
||||
$this->curl_error_message = curl_error($this->curl);
|
||||
$this->curl_error = !($this->curl_error_code === 0);
|
||||
$this->http_error_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
|
||||
$this->http_error = in_array(floor($this->http_error_code / 100), array(4, 5));
|
||||
$this->error = $this->curl_error || $this->http_error;
|
||||
|
||||
$this->request_headers = preg_split('/\r\n/', curl_getinfo($this->curl, CURLINFO_HEADER_OUT), NULL, PREG_SPLIT_NO_EMPTY);
|
||||
$this->response_headers = '';
|
||||
if (!(strpos($this->response, "\r\n\r\n") === FALSE)) {
|
||||
@@ -96,6 +100,7 @@ class Curl {
|
||||
list($this->response_headers, $this->response) = $parts;
|
||||
$this->response_headers = preg_split('/\r\n/', $this->response_headers, NULL, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
return $this->error_code;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ class CurlTest extends PHPUnit_Framework_TestCase {
|
||||
$test->curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
|
||||
$test->curl->get('http://1.2.3.4/');
|
||||
$this->assertTrue($test->curl->error === TRUE);
|
||||
$this->assertTrue($test->curl->error_code === CURLE_OPERATION_TIMEOUTED);
|
||||
$this->assertTrue($test->curl->curl_error_code === CURLE_OPERATION_TIMEOUTED);
|
||||
}
|
||||
|
||||
public function testHeaders() {
|
||||
|
||||
Reference in New Issue
Block a user