guzzle / guzzle

Guzzle, an extensible PHP HTTP client

Home Page:https://docs.guzzlephp.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The no proxy request option does not override proxies set in ENV vars

gergokee opened this issue · comments

Guzzle version(s) affected: 7.4.1
PHP version: 8.0.7 (hint: php --version)
cURL version: 7.29.0 (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 or https_proxy.

This is because the no option only applies the CURLOPT_PROXY if the host is not in the list. So when ignoring it doesn't apply the curl option so falling back to the proxy that is set in the ENV var.

How to reproduce
Create http_proxy & https_proxy ENV var pointing to a proxy.
Set the proxy => no request option to the host of a request.
Send a request and the proxy will be used and not ignored.

Possible Solution
The following lines of code in the CurlFactory.php:444 could be changed to set the CURLOPT_PROXY to an empty string when a proxy is not required.
From:

if (isset($options['proxy'][$scheme])) {
    $host = $easy->request->getUri()->getHost();
    if (!isset($options['proxy']['no']) || !Utils::isHostInNoProxy($host, $options['proxy']['no'])) {
        $conf[\CURLOPT_PROXY] = $options['proxy'][$scheme];
    }
}

To:

if (isset($options['proxy'][$scheme])) {
    $host = $easy->request->getUri()->getHost();
    if (isset($options['proxy']['no']) && Utils::isHostInNoProxy($host, $options['proxy']['no'])) {
        $conf[\CURLOPT_PROXY] = '';
    } else {
        $conf[\CURLOPT_PROXY] = $options['proxy'][$scheme];
    }
}

Additional context
Currently the no option can not be used by itself and requires the http or https settings to be applied also. Maybe consider refactoring this function to allow the no to be used even when the the other settings have not been used for cases when they have been set in the ENV vars.

This was an issue mentioned before but never got solved, solution is pretty simple, can we have this fixed please ?

can we have this fixed please

We are open to PRs to fix this. ;)