Skip to content

Commit

Permalink
encode#1105 raise warning if proxy scheme is http, https, all instead…
Browse files Browse the repository at this point in the history
… of http://, https://, all://
  • Loading branch information
cdeler committed Aug 4, 2020
1 parent d7aa6e0 commit 30d3ace
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,20 @@ def _get_proxy_map(
return {}
if isinstance(proxies, dict):
new_proxies = {}
filtered_proxy_keys = {"all", "http", "https"}
wrong_proxy_schemas = []
for key, value in proxies.items():
if key in filtered_proxy_keys:
wrong_proxy_schemas.append(key)
proxy = Proxy(url=value) if isinstance(value, (str, URL)) else value
new_proxies[str(key)] = proxy

if wrong_proxy_schemas:
valid_proxies = (f"{prefix}://" for prefix in wrong_proxy_schemas)
logger.warning(
f"You should use proxy schemes like {', '.join(valid_proxies)} "
f"instead of using {', '.join(wrong_proxy_schemas)}"
)
return new_proxies
else:
proxy = Proxy(url=proxies) if isinstance(proxies, (str, URL)) else proxies
Expand Down Expand Up @@ -485,22 +496,27 @@ def __init__(
app=app,
trust_env=trust_env,
)
self._proxies: typing.Dict[
URLPattern, typing.Optional[httpcore.SyncHTTPTransport]
] = {
URLPattern(key): None
if proxy is None
else self._init_proxy_transport(
proxy,
verify=verify,
cert=cert,
http2=http2,
limits=limits,
trust_env=trust_env,
proxies: typing.List[
typing.Tuple[URLPattern, typing.Optional[httpcore.SyncHTTPTransport]]
] = [
(
URLPattern(key),
None
if proxy is None
else self._init_proxy_transport(
proxy,
verify=verify,
cert=cert,
http2=http2,
limits=limits,
trust_env=trust_env,
),
)
for key, proxy in proxy_map.items()
}
self._proxies = dict(sorted(self._proxies.items()))
]
self._proxies: typing.Dict[
URLPattern, typing.Optional[httpcore.SyncHTTPTransport]
] = dict(sorted(proxies))

def _init_transport(
self,
Expand Down

0 comments on commit 30d3ace

Please sign in to comment.