diff --git a/examples/ip_resolve_4.php b/examples/ip_resolve_4.php new file mode 100644 index 000000000..aa70bb135 --- /dev/null +++ b/examples/ip_resolve_4.php @@ -0,0 +1,16 @@ + 1 +); +$request = Requests::get("https://www.google.com", array(), $options); + +// Check what we received +var_dump($request->body); \ No newline at end of file diff --git a/library/Requests.php b/library/Requests.php index d83ee09c0..7678b823a 100644 --- a/library/Requests.php +++ b/library/Requests.php @@ -344,7 +344,10 @@ public static function patch($url, $headers, $data = array(), $options = array() * - `data_format`: How should we send the `$data` parameter? * (string, one of 'query' or 'body', default: 'query' for * HEAD/GET/DELETE, 'body' for POST/PUT/OPTIONS/PATCH) - * + * - `ip_resolve` : Allows to select what kind of IP addresses to use when resolving host names. + * This is only interesting when using host names that resolve addresses using more than one version of IP, + * possible values are 0(resolve_whatever), 1(resolve_v4_only), 2(resolve_v6_only), otherwise will get ignored. + * (int, default: 0) * @throws Requests_Exception On invalid URLs (`nonhttp`) * * @param string $url URL to request @@ -358,6 +361,7 @@ public static function request($url, $headers = array(), $data = array(), $type if (empty($options['type'])) { $options['type'] = $type; } + $options = array_merge(self::get_default_options(), $options); self::set_defaults($url, $headers, $data, $type, $options); diff --git a/library/Requests/Transport/cURL.php b/library/Requests/Transport/cURL.php index 4429edb64..73562488c 100644 --- a/library/Requests/Transport/cURL.php +++ b/library/Requests/Transport/cURL.php @@ -159,6 +159,12 @@ public function request($url, $headers = array(), $data = array(), $options = ar curl_setopt($this->handle, CURLOPT_SSL_VERIFYHOST, 0); } + if (isset($options['ipresolve'])) { + if (in_array($options['ipresolve'], array(CURL_IPRESOLVE_WHATEVER, CURL_IPRESOLVE_V4, CURL_IPRESOLVE_V6))){ + curl_setopt($this->handle, CURLOPT_IPRESOLVE, $options['ipresolve']); + } + } + curl_exec($this->handle); $response = $this->response_data;