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(
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"))
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)
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,
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,
@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")