-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add support for GuzzleHTTP 'no' proxy #17684
Conversation
Thank you for taking care of this 👍 |
config/config.sample.php
Outdated
@@ -532,6 +532,13 @@ | |||
*/ | |||
'proxyuserpwd' => '', | |||
|
|||
/** | |||
* List of host names that should not be proxied to. | |||
* For example ``['.mit.edu', 'foo.com']``. |
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.
We might add some hint like:
Use something like
explode(',', getenv('NO_PROXY'))
to sync this value with the global NO_PROXY option.
d860915
to
0b27934
Compare
@mlatief could you rebase the branch? Thanks 👍 |
0b27934
to
acbc3b8
Compare
@mlatief Thanks a lot for this. Mind to do another rebase to trigger the CI again? |
acbc3b8
to
86047bf
Compare
Thanks, failures seem unrelated. |
Ah. I broke NO_PROXY and HTTPS_PROXY support with #14363 🙈
Take this a example:
Result:
To restore the default guzzle behaviour we MUST not set proxy as request option if there is no one. I can shoot another pr if this one is merged or @mlatief is willing clean up my mess ;) |
Would it be enough for example to modify this: server/lib/private/Http/Client/Client.php Lines 68 to 73 in 86047bf
proxy only if Nextcloud is configured to use one?
Also I would be interested in adding a test case for this, however I can't easily figure out a way to send the request to guzzle and see what values it used for |
Yes that's the right place. I'm not sure how to realize a test. But we actually should not test that guzzle is behaving correctly. Just ensure we pass the right data. |
86047bf
to
0b762a9
Compare
Now there is a check if In the process, I was reconsidering if 'proxy' should revert back to be just a URI string. However, that would mean that if Nextcloud is configured to use a 'proxy', there won't be an easy way Do you think if |
Good point 👍 I don't know to be honest. Guzzle uses
We are able to read a NO_PROXY value as fallback (for example if proxyexclude is not defined) but that mixes explicit and implicit configuration. For example: HTTPS_PROXY and NO_PROXY are defined. Admin want Nextcloud to use a different proxy. The NO_PROXY value does not work for the other proxy. With a fallback we would use the NO_PROXY value also for the other proxy. I would prefer: If a proxy is defined with Nextcloud also proxyexclude must be defined. A admin can still use getenv(NO_PROXY) to keep the value in sync with the system wide default. If we document it probably everyone should be happy. |
config/config.sample.php
Outdated
@@ -520,6 +520,10 @@ | |||
/** | |||
* The URL of your proxy server, for example ``proxy.example.com:8081``. | |||
* | |||
* Note: If a proxy is explicitly configured here, default values from proxy global |
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.
Guzzle (the http library used by Nextcloud) is reading the environment variables
HTTP_PROXY
(only for cli request),HTTPS_PROXY
andNO_PROXY
by default.If you configure
proxy
with Nextcloud any default configuration by Guzzle is overwritten. Make sure to setproxyexclude
accordingly if necessary.
lib/private/Http/Client/Client.php
Outdated
// Only add RequestOptions::PROXY if Nextcloud is explicitly | ||
// configured to use a proxy. This is needed in order not to override | ||
// Guzzle default values. | ||
if( $proxy !== null ) { |
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.
if( $proxy !== null ) { | |
if($proxy !== null) { |
lib/private/Http/Client/Client.php
Outdated
} | ||
|
||
return $proxyUserPwd . '@' . $proxyHost; | ||
return ['http' => $proxyHost, 'https' => $proxyHost, 'no' => $proxyExclude]; |
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.
If getenv('NO_PROXY')
is empty the no
element is not set. We should probably do the same. Only set no
if there is a value for proxyexclude.
The custom config allows to setup a proxy URI that is passed to GuzzleHTTP client as request options. Guzzle has the option to receive an array of proxies for each URI scheme as well as 'no' key value pair to provide a list of host names that should not be proxied to. Guzzle would automatically populate these options with HTTPS_PROXY and NO_PROXY environment variables. However, when providing a 'proxy' request option, default values will be overriden and it is required to explicitly provide the 'no' value if needed. More info: http://docs.guzzlephp.org/en/stable/request-options.html#proxy This commit will add support for a new config 'proxyexclude', which takes a list of host names to be excluded. It will also provide 'proxy' request option as an array instead of a string to Guzzle, and populate 'http' and 'https' URI schemes with proxy URI, and 'no' with 'proxyexclude' list. Also, if no 'proxy' is configured, it will leave out 'proxy' request option, so it won't override Guzzle default values. Sample config file includes a hint on how to explicitly sync 'proxyexclude' with NO_PROXY, and a note about default values. Signed-off-by: Mohammed Abdellatif <m.latief@gmail.com>
0b762a9
to
98d6415
Compare
Thanks for your first pull request and welcome to the community! Feel free to keep them coming! If you are looking for issues to tackle then have a look at this selection: https://github.com/nextcloud/server/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22 |
The custom config allows to setup a proxy URI that is passed to GuzzleHTTP client as request options. Guzzle has the option to receive an array of proxies for each URI scheme as well as 'no' key value pair
to provide a list of host names that should not be proxied to.
Guzzle would automatically populate this value with environment's NO_PROXY environment variable. However, when providing a 'proxy' request option, it is needed to provide the 'no' value.
More info:
http://docs.guzzlephp.org/en/stable/request-options.html#proxy
This commit will add support for new config 'proxyexclude', which takes a list of host names to be excluded.
It will also get 'proxy' request option as and array instead of a string to Guzzle, and populate 'http' and 'https' URI schemas with proxy URI, and 'no' with 'proxyexclude' list.
Should fix: #12402
Signed-off-by: Mohammed Abdellatif m.latief@gmail.com