From d07ba2661df659aafa3818f34a401a102c93cfaa Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 1 May 2020 15:44:29 -0400 Subject: [PATCH] Update WireHttp to allow for custom "setopt" options when using CURL --- wire/core/WireHttp.php | 25 ++++++++++++++++++++++--- wire/core/WireInput.php | 4 ++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/wire/core/WireHttp.php b/wire/core/WireHttp.php index 0130d058..2a9ecc89 100644 --- a/wire/core/WireHttp.php +++ b/wire/core/WireHttp.php @@ -588,9 +588,13 @@ class WireHttp extends Wire { $timeout = isset($options['timeout']) ? (float) $options['timeout'] : $this->getTimeout(); $proxy = ''; - if(!empty($options['proxy'])) $proxy = $options['proxy']; - else if(isset($options['curl']) && !empty($options['curl']['http']['proxy'])) $proxy = $options['curl']['http']['proxy']; - else if(isset($options['http']) && !empty($options['http']['proxy'])) $proxy = $options['http']['proxy']; + if(!empty($options['proxy'])) { + $proxy = $options['proxy']; + } else if(isset($options['curl']) && !empty($options['curl']['http']['proxy'])) { + $proxy = $options['curl']['http']['proxy']; + } else if(isset($options['http']) && !empty($options['http']['proxy'])) { + $proxy = $options['http']['proxy']; + } $curl = curl_init(); @@ -662,6 +666,21 @@ class WireHttp extends Wire { }); curl_setopt($curl, CURLOPT_URL, $url); + + // custom CURL options provided in $options array + if(!empty($options['curl']) && !empty($options['curl']['setopt'])) { + $setopts = $options['curl']['setopt']; + } else if(!empty($options['curl_setopt'])) { + $setopts = $options['curl_setopt']; + } else { + $setopts = null; + } + if(is_array($setopts)) { + foreach($setopts as $opt => $optVal) { + curl_setopt($curl, $opt, $optVal); + } + } + $result = curl_exec($curl); if($result === false) { diff --git a/wire/core/WireInput.php b/wire/core/WireInput.php index b9cdc293..e3d27ecf 100644 --- a/wire/core/WireInput.php +++ b/wire/core/WireInput.php @@ -393,7 +393,7 @@ class WireInput extends Wire { * * - If given a wildcard string, it will return the first matching URL segment. For example, * the wildcard string `foo-*` would match the first URL segment to begin with “foo-”, - * so any of these segments would match & be returned: `foo-bar`, `foo-12345`, foo-baz123`. + * so any of these segments would match & be returned: `foo-bar`, `foo-12345`, `foo-baz123`. * A wildcard string of `*bar` would match anything ending with “bar”, i.e. it would match * and return `foo-bar`, `foobar`, `baz_123bar`, etc. * @@ -410,7 +410,7 @@ class WireInput extends Wire { * - If you want to focus any of the above options upon a URL segment at a specific index, * then you can append the index number to the method name. For example, if you want it to * just focus on URL segment #1, then call `$input->urlSegment1(…)`, or for URL segment #2 - * yoyu would call `$input-urlSegment2(…)`, and so on. + * you would call `$input->urlSegment2(…)`, and so on. * * Please also note the following about URL segments: *