]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Setting `app=...` or `transport=...` should bypass environment proxies. (#1122)
authorTom Christie <tom@tomchristie.com>
Sun, 2 Aug 2020 11:42:36 +0000 (12:42 +0100)
committerGitHub <noreply@github.com>
Sun, 2 Aug 2020 11:42:36 +0000 (12:42 +0100)
* Setting app= or transport= should bypass proxies

* Tweak

httpx/_client.py

index 4110fd7d9696a6565f74e152512866e633dbdb6b..e4b212b4ac99450132911e9a36f665d5fb3470a8 100644 (file)
@@ -89,10 +89,10 @@ class BaseClient:
         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 @@ class Client(BaseClient):
             )
             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 @@ class AsyncClient(BaseClient):
             )
             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,