1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 02:04:35 +02:00

Update WireHttp to allow for custom "setopt" options when using CURL

This commit is contained in:
Ryan Cramer
2020-05-01 15:44:29 -04:00
parent 3ab31805c6
commit d07ba2661d
2 changed files with 24 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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:
*