Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cURL's version_number and cleanup the version_compare() stuff #104

Merged
merged 1 commit into from
Mar 23, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions library/Requests/Transport/cURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* @subpackage Transport
*/
class Requests_Transport_cURL implements Requests_Transport {
const CURL_7_10_5 = 0x070A05;
const CURL_7_16_2 = 0x071002;

/**
* Raw HTTP data
*
Expand All @@ -30,7 +33,7 @@ class Requests_Transport_cURL implements Requests_Transport {
/**
* Version string
*
* @var string
* @var long
*/
public $version;

Expand Down Expand Up @@ -60,12 +63,12 @@ class Requests_Transport_cURL implements Requests_Transport {
*/
public function __construct() {
$curl = curl_version();
$this->version = $curl['version'];
$this->version = $curl['version_number'];
$this->fp = curl_init();

curl_setopt($this->fp, CURLOPT_HEADER, false);
curl_setopt($this->fp, CURLOPT_RETURNTRANSFER, 1);
if (version_compare($this->version, '7.10.5', '>=')) {
if ($this->version >= self::CURL_7_10_5) {
curl_setopt($this->fp, CURLOPT_ENCODING, '');
}
if (defined('CURLOPT_PROTOCOLS')) {
Expand Down Expand Up @@ -249,12 +252,12 @@ protected function setup_handle($url, $headers, $data, $options) {
break;
}

if( is_int($options['timeout']) or version_compare($this->version, '7.16.2', '<') ) {
if( is_int($options['timeout']) or $this->version < self::CURL_7_16_2 ) {
curl_setopt($this->fp, CURLOPT_TIMEOUT, ceil($options['timeout']));
} else {
curl_setopt($this->fp, CURLOPT_TIMEOUT_MS, round($options['timeout'] * 1000) );
}
if( is_int($options['connect_timeout']) or version_compare($this->version, '7.16.2', '<') ) {
if( is_int($options['connect_timeout']) or $this->version < self::CURL_7_16_2 ) {
curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT, ceil($options['connect_timeout']));
} else {
curl_setopt($this->fp, CURLOPT_CONNECTTIMEOUT_MS, round($options['connect_timeout'] * 1000));
Expand Down