Skip to content
Myr

Enable NO_PROXY environment variable support (#835)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Enabling NO_PROXY env support * Enabling NO_PROXY env var support and writing tests * Update tests/client/test_proxies.py Co-Authored-By: Florimond Manca <florimond.manca@gmail.com> * Update tests/client/test_proxies.py Co-Authored-By: Florimond Manca <florimond.manca@gmail.com>

authored by Evan Lurvey · committed by GitHub · parent 3333152 · Browse files · 2 files+37 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Diff stats

2 files+37 added−3 removed

  • tests:+29 added−0 removed
  • other:+8 added−3 removed

2 files+37 added−3 removed

modified:httpx/_client.py+8 added-3 removed
41 unmodified lines
42 Response,43 URLTypes,44)45from ._status_codes import codes46from ._utils import NetRCInfo, get_environment_proxies, get_logger46from ._utils import (47 NetRCInfo,48 get_environment_proxies,49 get_logger,50 should_not_be_proxied,51)5253logger = get_logger(__name__)5455
465 unmodified lines
521 """522 Returns the SyncDispatcher instance that should be used for a given URL.523 This will either be the standard connection pool, or a proxy.524 """520 if self.proxies:525 if self.proxies and not should_not_be_proxied(url):526 is_default_port = (url.scheme == "http" and url.port == 80) or (527 url.scheme == "https" and url.port == 443528 )529 hostname = f"{url.host}:{url.port}"
506 unmodified lines
1036 """1037 Returns the AsyncDispatcher instance that should be used for a given URL.1038 This will either be the standard connection pool, or a proxy.1039 """1035 if self.proxies:1040 if self.proxies and not should_not_be_proxied(url):1041 is_default_port = (url.scheme == "http" and url.port == 80) or (1042 url.scheme == "https" and url.port == 4431043 )1044 hostname = f"{url.host}:{url.port}"
418 unmodified lines
modified:tests/client/test_proxies.py+29 added
85 unmodified lines
8687def test_unsupported_proxy_scheme():88 with pytest.raises(ValueError):89 httpx.AsyncClient(proxies="ftp://127.0.0.1")909192@pytest.mark.parametrize(93 ["url", "env", "expected"],94 [95 ("http://google.com", {}, None),96 (97 "http://google.com",98 {"HTTP_PROXY": "http://example.com"},99 "http://example.com",100 ),101 (102 "http://google.com",103 {"HTTP_PROXY": "http://example.com", "NO_PROXY": "google.com"},104 None,105 ),106 ],107)108def test_proxies_environ(monkeypatch, url, env, expected):109 for name, value in env.items():110 monkeypatch.setenv(name, value)111112 client = httpx.AsyncClient()113 dispatcher = client.dispatcher_for_url(httpx.URL(url))114115 if expected is None:116 assert dispatcher == client.dispatch117 else:118 assert dispatcher.proxy_url == expected