diff --git a/httpx/_client.py b/httpx/_client.py index 4110fd7d96..e4b212b4ac 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -89,10 +89,10 @@ def trust_env(self) -> bool: return self._trust_env def _get_proxy_map( - self, proxies: typing.Optional[ProxiesTypes], trust_env: bool, + self, proxies: typing.Optional[ProxiesTypes], allow_env_proxies: bool, ) -> typing.Dict[str, typing.Optional[Proxy]]: if proxies is None: - if trust_env: + if allow_env_proxies: return { key: None if url is None else Proxy(url=url) for key, url in get_environment_proxies().items() @@ -473,7 +473,8 @@ def __init__( ) limits = pool_limits - proxy_map = self._get_proxy_map(proxies, trust_env) + allow_env_proxies = trust_env and app is None and transport is None + proxy_map = self._get_proxy_map(proxies, allow_env_proxies) self._transport = self._init_transport( verify=verify, @@ -1003,7 +1004,8 @@ def __init__( ) limits = pool_limits - proxy_map = self._get_proxy_map(proxies, trust_env) + allow_env_proxies = trust_env and app is None and transport is None + proxy_map = self._get_proxy_map(proxies, allow_env_proxies) self._transport = self._init_transport( verify=verify,