@@ -110,10 +110,11 @@ public static function clearDefaultHeaders()
110
110
* Set curl options to send on every request
111
111
*
112
112
* @param array $options options array
113
+ * @return array
113
114
*/
114
- public static function curlOpts ($ opts )
115
+ public static function curlOpts ($ options )
115
116
{
116
- return array_merge (self ::$ curlOpts , $ opts );
117
+ return self :: mergeCurlOptions (self ::$ curlOpts , $ options );
117
118
}
118
119
119
120
/**
@@ -405,7 +406,7 @@ public static function send($method, $url, $body = null, $headers = array(), $us
405
406
$ url .= urldecode (http_build_query (self ::buildHTTPCurlQuery ($ body )));
406
407
}
407
408
408
- curl_setopt_array ( self :: $ handle , array (
409
+ $ curl_base_options = [
409
410
CURLOPT_URL => self ::encodeUrl ($ url ),
410
411
CURLOPT_RETURNTRANSFER => true ,
411
412
CURLOPT_FOLLOWLOCATION => true ,
@@ -417,10 +418,9 @@ public static function send($method, $url, $body = null, $headers = array(), $us
417
418
CURLOPT_SSL_VERIFYHOST => self ::$ verifyHost === false ? 0 : 2 ,
418
419
// If an empty string, '', is set, a header containing all supported encoding types is sent
419
420
CURLOPT_ENCODING => ''
420
- ));
421
-
422
- // update options
423
- curl_setopt_array (self ::$ handle , self ::$ curlOpts );
421
+ ];
422
+
423
+ curl_setopt_array (self ::$ handle , self ::mergeCurlOptions ($ curl_base_options , self ::$ curlOpts ));
424
424
425
425
if (self ::$ socketTimeout !== null ) {
426
426
curl_setopt (self ::$ handle , CURLOPT_TIMEOUT , self ::$ socketTimeout );
@@ -558,4 +558,15 @@ private static function getHeaderString($key, $val)
558
558
$ key = trim (strtolower ($ key ));
559
559
return $ key . ': ' . $ val ;
560
560
}
561
+
562
+ /**
563
+ * @param array $existing_options
564
+ * @param array $new_options
565
+ * @return array
566
+ */
567
+ private static function mergeCurlOptions (&$ existing_options , $ new_options )
568
+ {
569
+ $ existing_options = $ new_options + $ existing_options ;
570
+ return $ existing_options ;
571
+ }
561
572
}
0 commit comments