From f57a3ac43c11424bd9643f7f5b06d3ee58be9b40 Mon Sep 17 00:00:00 2001 From: Shivam Yuvraj Date: Wed, 11 Dec 2019 19:07:18 +0530 Subject: [PATCH 1/2] feature to set ip resolver type in request options --- library/Requests/Transport/cURL.php | 6 ++++++ 1 file changed, 6 insertions(+) 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; From 3a8caf82a63fd9d330812d6892aa2b577d8bd1c3 Mon Sep 17 00:00:00 2001 From: Shivam Yuvraj Date: Thu, 12 Dec 2019 13:19:55 +0530 Subject: [PATCH 2/2] added example and comment for ip_resolve_4 --- examples/ip_resolve_4.php | 16 ++++++++++++++++ library/Requests.php | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 examples/ip_resolve_4.php 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);