From f24458861ef4c925c5c42afe7ed76c3e0ad16642 Mon Sep 17 00:00:00 2001 From: camellia256 Date: Fri, 11 Oct 2019 06:14:07 +0800 Subject: [PATCH 1/4] remove redundant code --- httpx/utils.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/httpx/utils.py b/httpx/utils.py index 8aea5e7119..801d1dc953 100644 --- a/httpx/utils.py +++ b/httpx/utils.py @@ -219,30 +219,12 @@ 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 = { + return { key: val for key, val in getproxies().items() if ("://" in key or key in ("http", "https")) } - # 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 From 646385b2e115e69448cb7bf1152da83788fa3c56 Mon Sep 17 00:00:00 2001 From: camellia256 Date: Fri, 11 Oct 2019 06:20:29 +0800 Subject: [PATCH 2/4] filter supported proxy protocols explicitly --- httpx/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/httpx/utils.py b/httpx/utils.py index 801d1dc953..b1f9c914ea 100644 --- a/httpx/utils.py +++ b/httpx/utils.py @@ -219,10 +219,11 @@ 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'. + SUPPORTED_PROXY_PROTOCOLS = ("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_PROTOCOLS) } From 025cb598259d66aaf20421df80d03e8e538be736 Mon Sep 17 00:00:00 2001 From: camellia256 Date: Fri, 11 Oct 2019 06:24:11 +0800 Subject: [PATCH 3/4] only test proxy filtering --- tests/test_utils.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 9e8169c7f9..800928c993 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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"}, {}), ], ) From ceb9fd17c7a1a6ed2984b15943824b82bd3e70af Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Sat, 12 Oct 2019 10:32:16 -0500 Subject: [PATCH 4/4] Update utils.py --- httpx/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpx/utils.py b/httpx/utils.py index b1f9c914ea..c16341c5f9 100644 --- a/httpx/utils.py +++ b/httpx/utils.py @@ -219,11 +219,11 @@ 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'. - SUPPORTED_PROXY_PROTOCOLS = ("http", "https", "all") + supported_proxy_schemes = ("http", "https", "all") return { key: val for key, val in getproxies().items() - if ("://" in key or key in SUPPORTED_PROXY_PROTOCOLS) + if ("://" in key or key in supported_proxy_schemes) }