From 0e7730bcccf51a6ca5b66d2dc6cab40f2a1660a3 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sun, 2 Aug 2020 12:42:36 +0100 Subject: [PATCH] Setting `app=...` or `transport=...` should bypass environment proxies. (#1122) * Setting app= or transport= should bypass proxies * Tweak --- httpx/_client.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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,