Merge pull request #88 from frankdee/master
improved solution to override cURL options …
This commit is contained in:
@@ -110,10 +110,11 @@ class Request
|
|||||||
* Set curl options to send on every request
|
* Set curl options to send on every request
|
||||||
*
|
*
|
||||||
* @param array $options options array
|
* @param array $options options array
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function curlOpts($opts)
|
public static function curlOpts($options)
|
||||||
{
|
{
|
||||||
return array_merge(self::$curlOpts, $opts);
|
return self::mergeCurlOptions(self::$curlOpts, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -405,7 +406,7 @@ class Request
|
|||||||
$url .= urldecode(http_build_query(self::buildHTTPCurlQuery($body)));
|
$url .= urldecode(http_build_query(self::buildHTTPCurlQuery($body)));
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt_array(self::$handle, array(
|
$curl_base_options = [
|
||||||
CURLOPT_URL => self::encodeUrl($url),
|
CURLOPT_URL => self::encodeUrl($url),
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_FOLLOWLOCATION => true,
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
@@ -417,10 +418,9 @@ class Request
|
|||||||
CURLOPT_SSL_VERIFYHOST => self::$verifyHost === false ? 0 : 2,
|
CURLOPT_SSL_VERIFYHOST => self::$verifyHost === false ? 0 : 2,
|
||||||
// If an empty string, '', is set, a header containing all supported encoding types is sent
|
// If an empty string, '', is set, a header containing all supported encoding types is sent
|
||||||
CURLOPT_ENCODING => ''
|
CURLOPT_ENCODING => ''
|
||||||
));
|
];
|
||||||
|
|
||||||
// update options
|
curl_setopt_array(self::$handle, self::mergeCurlOptions($curl_base_options, self::$curlOpts));
|
||||||
curl_setopt_array(self::$handle, self::$curlOpts);
|
|
||||||
|
|
||||||
if (self::$socketTimeout !== null) {
|
if (self::$socketTimeout !== null) {
|
||||||
curl_setopt(self::$handle, CURLOPT_TIMEOUT, self::$socketTimeout);
|
curl_setopt(self::$handle, CURLOPT_TIMEOUT, self::$socketTimeout);
|
||||||
@@ -558,4 +558,15 @@ class Request
|
|||||||
$key = trim(strtolower($key));
|
$key = trim(strtolower($key));
|
||||||
return $key . ': ' . $val;
|
return $key . ': ' . $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $existing_options
|
||||||
|
* @param array $new_options
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function mergeCurlOptions(&$existing_options, $new_options)
|
||||||
|
{
|
||||||
|
$existing_options = $new_options + $existing_options;
|
||||||
|
return $existing_options;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user