-
-
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
The no proxy request option does not avoid falling back to proxies set in ENV vars #3163
Comments
yep, the reason i set CURLOPT_PROXY to empty cause older php versions had a bug where the CURLOPT_NOPROXY was not taken into account. But my first fix was wrong, unset() is doing nothing. So we need another fix then. I like the first solution if that is stable in latest php versions. UPDATE: let's do both, that will cover all PHP versions. |
Is there any hope for adding this to the next release? :) |
I've hit this bug in a similar case. My intention was to configure guzzle's proxy behavior to override/ignore the environment (variables) I tried this approach: 'proxy' => [
'http' => 'http://example:8080',
'https' => 'http://example:8080',
# Send everything through the proxy
'no' => []
] And I found that the environment variable's My workaround was: diff --git a/src/Handler/CurlFactory.php b/src/Handler/CurlFactory.php
index 16a94223..59b79da2 100644
--- a/src/Handler/CurlFactory.php
+++ b/src/Handler/CurlFactory.php
@@ -448,6 +448,9 @@ class CurlFactory implements CurlFactoryInterface
if (isset($options['proxy']['no']) && Utils::isHostInNoProxy($host, $options['proxy']['no'])) {
unset($conf[\CURLOPT_PROXY]);
} else {
+ $conf[\CURLOPT_NOPROXY] = "";
$conf[\CURLOPT_PROXY] = $options['proxy'][$scheme];
}
} So there are at least two cases to consider here:
Either of these will result in unexpected behavior. |
Guzzle version(s) affected: 7.7
PHP version: 8.1.22 (hint:
php --version
)cURL version: 8.2.1 (hint:
php -i | grep cURL
)Description
When using the
proxy
=>no
request option guzzle fails to ignore the proxy if ENV vars are present on the server i.e.http_proxy
orhttps_proxy
.The issue was introduced in #3093 . Original solution in the first commit e0de379 (setting
CURLOPT_PROXY
to an empty string) solved the problem but due to a failing test a proposed final fix to unset it withunset($conf[\CURLOPT_PROXY]);
does not actually do anything as the$conf[\CURLOPT_PROXY]
option is never defined before being unset.How to reproduce
Create
http_proxy
&https_proxy
ENV var pointing to a proxy.Create
no_proxy
ENV var and make sure it does not include the host that we are about to send a test request to.Set the
proxy
=>no
request option to the host of a request.Send a request and the proxy sittings of the ENV will be used.
Possible Solution
The following lines of code in the CurlFactory.php:448 could be changed to set the CURLOPT_NOPROXY to a requesting host string when a proxy is not required.
From:
To:
Additional context
Another solution is to force the
$conf[\CURLOPT_PROXY]
option to en empty string as it was originally proposed in e0de379 but then the test CurlFactoryTest.php:194 should be updated from:to:
The text was updated successfully, but these errors were encountered: