]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Rely on getproxies for all proxy environment variables (#470)
authorcamellia256 <camellia256@outlook.com>
Sat, 12 Oct 2019 15:34:50 +0000 (23:34 +0800)
committerSeth Michael Larson <sethmichaellarson@gmail.com>
Sat, 12 Oct 2019 15:34:50 +0000 (10:34 -0500)
httpx/utils.py
tests/test_utils.py

index 8aea5e7119338f44de6c70748d3b97941989cda0..c16341c5f96e1ba9b834efe2612d09193ebdb920 100644 (file)
@@ -219,30 +219,13 @@ def get_environment_proxies() -> typing.Dict[str, str]:
     # Registry and Config for proxies on Windows and macOS.
     # We don't want to propagate non-HTTP proxies into
     # our configuration such as 'TRAVIS_APT_PROXY'.
-    proxies = {
+    supported_proxy_schemes = ("http", "https", "all")
+    return {
         key: val
         for key, val in getproxies().items()
-        if ("://" in key or key in ("http", "https"))
+        if ("://" in key or key in supported_proxy_schemes)
     }
 
-    # Favor lowercase environment variables over uppercase.
-    all_proxy = get_environ_lower_and_upper("ALL_PROXY")
-    if all_proxy is not None:
-        proxies["all"] = all_proxy
-
-    return proxies
-
-
-def get_environ_lower_and_upper(key: str) -> typing.Optional[str]:
-    """Gets a value from os.environ with both the lowercase and uppercase
-    environment variable. Prioritizes the lowercase environment variable.
-    """
-    for key in (key.lower(), key.upper()):
-        value = os.environ.get(key, None)
-        if value is not None and isinstance(value, str):
-            return value
-    return None
-
 
 def to_bytes(value: typing.Union[str, bytes], encoding: str = "utf-8") -> bytes:
     return value.encode(encoding) if isinstance(value, str) else value
index 9e8169c7f9e22143645dd8dd1693f08c5e65af39..800928c993a7faa12ed62ffe30a3628eb67fdd96 100644 (file)
@@ -178,14 +178,7 @@ async def test_elapsed_timer():
             {"https_proxy": "http://127.0.0.1", "HTTP_PROXY": "https://127.0.0.1"},
             {"https": "http://127.0.0.1", "http": "https://127.0.0.1"},
         ),
-        (
-            {"all_proxy": "http://127.0.0.1", "ALL_PROXY": "https://1.1.1.1"},
-            {"all": "http://127.0.0.1"},
-        ),
-        (
-            {"https_proxy": "http://127.0.0.1", "HTTPS_PROXY": "https://1.1.1.1"},
-            {"https": "http://127.0.0.1"},
-        ),
+        ({"all_proxy": "http://127.0.0.1"}, {"all": "http://127.0.0.1"}),
         ({"TRAVIS_APT_PROXY": "http://127.0.0.1"}, {}),
     ],
 )