Skip to content
Myr

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

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

authored by Tom Christie · committed by GitHub · parent 20e66d2 · Browse files · 3 files+7 added−25 removed
This commit

State

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

Diff stats

3 files+7 added−25 removed

  • tests:+5 added−12 removed
  • other:+2 added−13 removed

3 files+7 added−25 removed

modified:httpx/_transports/default.py-2 removed
143 unmodified lines
144 else:145 self._pool = httpcore.SyncHTTPProxy(146 proxy_url=proxy.url.raw,147 proxy_headers=proxy.headers.raw,148 proxy_mode=proxy.mode,148 ssl_context=ssl_context,149 max_connections=limits.max_connections,150 max_keepalive_connections=limits.max_keepalive_connections,151 keepalive_expiry=limits.keepalive_expiry,
88 unmodified lines
240 else:241 self._pool = httpcore.AsyncHTTPProxy(242 proxy_url=proxy.url.raw,243 proxy_headers=proxy.headers.raw,245 proxy_mode=proxy.mode,244 ssl_context=ssl_context,245 max_connections=limits.max_connections,246 max_keepalive_connections=limits.max_keepalive_connections,247 keepalive_expiry=limits.keepalive_expiry,
47 unmodified lines
modified:httpx/_config.py+2 added-11 removed
314 unmodified lines
315 )316317318class Proxy:319 def __init__(320 self, url: URLTypes, *, headers: HeaderTypes = None, mode: str = "DEFAULT"321 ):319 def __init__(self, url: URLTypes, *, headers: HeaderTypes = None):320 url = URL(url)321 headers = Headers(headers)322323 if url.scheme not in ("http", "https"):324 raise ValueError(f"Unknown scheme for proxy URL {url!r}")327 if mode not in ("DEFAULT", "FORWARD_ONLY", "TUNNEL_ONLY"):328 raise ValueError(f"Unknown proxy mode {mode!r}")325326 if url.username or url.password:327 headers.setdefault(328 "Proxy-Authorization",
4 unmodified lines
333 url = url.copy_with(username=None, password=None)334335 self.url = url336 self.headers = headers341 self.mode = mode337338 def _build_auth_header(self, username: str, password: str) -> str:339 userpass = (username.encode("utf-8"), password.encode("utf-8"))340 token = b64encode(b":".join(userpass)).decode()341 return f"Basic {token}"342343 def __repr__(self) -> str:349 return (350 f"Proxy(url={str(self.url)!r}, "351 f"headers={dict(self.headers)!r}, "352 f"mode={self.mode!r})"353 )344 return f"Proxy(url={str(self.url)!r}, headers={dict(self.headers)!r})"345346347DEFAULT_TIMEOUT_CONFIG = Timeout(timeout=5.0)348DEFAULT_LIMITS = Limits(max_connections=100, max_keepalive_connections=20)
1 unmodified line
modified:tests/test_config.py+5 added-12 removed
198 unmodified lines
199 assert context.keylog_filename is None # type: ignore200201202@pytest.mark.parametrize(203 "url,expected_url,expected_headers,expected_mode",203 "url,expected_url,expected_headers",204 [205 ("https://example.com", "https://example.com", {}, "DEFAULT"),205 ("https://example.com", "https://example.com", {}),206 (207 "https://user:pass@example.com",208 "https://example.com",209 {"proxy-authorization": "Basic dXNlcjpwYXNz"},210 "DEFAULT",210 ),211 ],212)214def test_proxy_from_url(url, expected_url, expected_headers, expected_mode):213def test_proxy_from_url(url, expected_url, expected_headers):214 proxy = httpx.Proxy(url)215216 assert str(proxy.url) == expected_url217 assert dict(proxy.headers) == expected_headers219 assert proxy.mode == expected_mode220 assert repr(proxy) == "Proxy(url='{}', headers={}, mode='{}')".format(221 expected_url, str(expected_headers), expected_mode218 assert repr(proxy) == "Proxy(url='{}', headers={})".format(219 expected_url, str(expected_headers)220 )221222223def test_invalid_proxy_scheme():224 with pytest.raises(ValueError):225 httpx.Proxy("invalid://example.com")228229230def test_invalid_proxy_mode():231 with pytest.raises(ValueError):232 httpx.Proxy("https://example.com", mode="INVALID")