Skip to content
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

Merged
merged 1 commit into from
Nov 6, 2016

Conversation

paveljanda
Copy link
Contributor

No description provided.

Copy link
Member

@sagikazarmark sagikazarmark left a 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')) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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());
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roger that.

@paveljanda
Copy link
Contributor Author

@sagikazarmark Is it all right now?

@sagikazarmark
Copy link
Member

Can you please also add some documentation?

https://github.com/guzzle/guzzle/blob/master/docs/request-options.rst

@paveljanda
Copy link
Contributor Author

There it is.

.. force_ipv4-option:

force_ipv4
---------------
Copy link
Member

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?

Copy link
Contributor Author

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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make "true" lowercase

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

@sagikazarmark
Copy link
Member

@guzzle/maintainers please add some input here

@mtdowling
Copy link
Member

Could this be more general -- like force_ip_resolve => v4?

@paveljanda paveljanda changed the title Added cofiguration option to force client to use ipv4 protocol (curl) Added cofiguration option to force client to use only ipv4 or ipv6 protocol (curl) Oct 14, 2016
@paveljanda
Copy link
Contributor Author

@mtdowling Sure, great idea. Updated.

@paveljanda paveljanda changed the title Added cofiguration option to force client to use only ipv4 or ipv6 protocol (curl) Added cofiguration option to force client to use either ipv4 or ipv6 protocol (curl) Oct 14, 2016
@Nyholm
Copy link
Member

Nyholm commented Oct 25, 2016

Are we happy with the changes here?

@sagikazarmark
Copy link
Member

I am, it's also in the "Ready to merge" section in the Contribution project.

@sagikazarmark sagikazarmark merged commit 9f75c64 into guzzle:master Nov 6, 2016
@sagikazarmark
Copy link
Member

Thanks @paveljanda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants