Drop mode argument, 'httpx.Proxy(..., mode=...)' (#1795)

This commit is contained in:
Tom Christie 2021-08-13 11:34:56 +01:00 committed by GitHub
parent 20e66d2048
commit 77246617ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 25 deletions

View File

@ -316,16 +316,12 @@ class Limits:
class Proxy:
def __init__(
self, url: URLTypes, *, headers: HeaderTypes = None, mode: str = "DEFAULT"
):
def __init__(self, url: URLTypes, *, headers: HeaderTypes = None):
url = URL(url)
headers = Headers(headers)
if url.scheme not in ("http", "https"):
raise ValueError(f"Unknown scheme for proxy URL {url!r}")
if mode not in ("DEFAULT", "FORWARD_ONLY", "TUNNEL_ONLY"):
raise ValueError(f"Unknown proxy mode {mode!r}")
if url.username or url.password:
headers.setdefault(
@ -338,7 +334,6 @@ class Proxy:
self.url = url
self.headers = headers
self.mode = mode
def _build_auth_header(self, username: str, password: str) -> str:
userpass = (username.encode("utf-8"), password.encode("utf-8"))
@ -346,11 +341,7 @@ class Proxy:
return f"Basic {token}"
def __repr__(self) -> str:
return (
f"Proxy(url={str(self.url)!r}, "
f"headers={dict(self.headers)!r}, "
f"mode={self.mode!r})"
)
return f"Proxy(url={str(self.url)!r}, headers={dict(self.headers)!r})"
DEFAULT_TIMEOUT_CONFIG = Timeout(timeout=5.0)

View File

@ -145,7 +145,6 @@ class HTTPTransport(BaseTransport):
self._pool = httpcore.SyncHTTPProxy(
proxy_url=proxy.url.raw,
proxy_headers=proxy.headers.raw,
proxy_mode=proxy.mode,
ssl_context=ssl_context,
max_connections=limits.max_connections,
max_keepalive_connections=limits.max_keepalive_connections,
@ -242,7 +241,6 @@ class AsyncHTTPTransport(AsyncBaseTransport):
self._pool = httpcore.AsyncHTTPProxy(
proxy_url=proxy.url.raw,
proxy_headers=proxy.headers.raw,
proxy_mode=proxy.mode,
ssl_context=ssl_context,
max_connections=limits.max_connections,
max_keepalive_connections=limits.max_keepalive_connections,

View File

@ -200,33 +200,26 @@ def test_ssl_config_support_for_keylog_file(tmpdir, monkeypatch): # pragma: noc
@pytest.mark.parametrize(
"url,expected_url,expected_headers,expected_mode",
"url,expected_url,expected_headers",
[
("https://example.com", "https://example.com", {}, "DEFAULT"),
("https://example.com", "https://example.com", {}),
(
"https://user:pass@example.com",
"https://example.com",
{"proxy-authorization": "Basic dXNlcjpwYXNz"},
"DEFAULT",
),
],
)
def test_proxy_from_url(url, expected_url, expected_headers, expected_mode):
def test_proxy_from_url(url, expected_url, expected_headers):
proxy = httpx.Proxy(url)
assert str(proxy.url) == expected_url
assert dict(proxy.headers) == expected_headers
assert proxy.mode == expected_mode
assert repr(proxy) == "Proxy(url='{}', headers={}, mode='{}')".format(
expected_url, str(expected_headers), expected_mode
assert repr(proxy) == "Proxy(url='{}', headers={})".format(
expected_url, str(expected_headers)
)
def test_invalid_proxy_scheme():
with pytest.raises(ValueError):
httpx.Proxy("invalid://example.com")
def test_invalid_proxy_mode():
with pytest.raises(ValueError):
httpx.Proxy("https://example.com", mode="INVALID")