-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added cofiguration option to force client to use either ipv4 or ipv6 protocol (curl) #1608
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Can you please take a look at my comments?
@@ -375,6 +375,14 @@ private function applyHandlerOptions(EasyHandle $easy, array &$conf) | |||
$conf[CURLOPT_TIMEOUT_MS] = $options['timeout'] * 1000; | |||
} | |||
|
|||
if (isset($options['force_ipv4'])) { | |||
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From which PHP version is this feature available? Is it PHP version dependent at all? For me it looks a little bit weird that we check the feature and then refer to the PHP version. I would rather check the PHP version (if that's still necessary) or say this curl feature is not available. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Id should not be dependent on any PHP version. It just won't work when the curl library is not present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if this feature comes with every version of curl and php, why do you need to check it's existence? Just two lines bellow another curl constant is used and it doesn't check curl existence, not to mention that it is CURL factory so it might probably be clear by this time if curl is present or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I will remove the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) { | ||
$conf[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; | ||
} else { | ||
throw new \RuntimeException('Can not force client to use IPV4 protocol on php version ' . phpversion()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do the check in a reverse order? If the feature is not available throw an exception else just continue running. (You don't even need the else branch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roger that.
@sagikazarmark Is it all right now? |
Can you please also add some documentation? https://github.com/guzzle/guzzle/blob/master/docs/request-options.rst |
There it is. |
.. force_ipv4-option: | ||
|
||
force_ipv4 | ||
--------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please trim dashes to the length of the option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
.. code-block:: php | ||
|
||
// Force ipv4 protocol | ||
$client->request('GET', '/foo', [GuzzleHttp\RequestOptions::FORCE_IPV4 => TRUE]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make "true" lowercase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the standard is that you use the option name as string, not the constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1, Done.
2, Done, but i strongly recommend to use the constant, not the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted and agreed, but for the sake of consistency, we leave the string there
@guzzle/maintainers please add some input here |
Could this be more general -- like force_ip_resolve => v4? |
@mtdowling Sure, great idea. Updated. |
Are we happy with the changes here? |
I am, it's also in the "Ready to merge" section in the Contribution project. |
Thanks @paveljanda |
No description provided.