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 8e02fce
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
import httpcore

from ._auth import Auth, BasicAuth, FunctionAuth
from ._config import (
DEFAULT_LIMITS,
DEFAULT_MAX_REDIRECTS,
DEFAULT_TIMEOUT_CONFIG,
UNSET,
Limits,
Proxy,
Timeout,
UnsetType,
create_ssl_context,
)
from ._config import (DEFAULT_LIMITS, DEFAULT_MAX_REDIRECTS, DEFAULT_TIMEOUT_CONFIG, Limits, Proxy, Timeout, UNSET,
UnsetType, create_ssl_context)
from ._content_streams import ContentStream
from ._exceptions import (
HTTPCORE_EXC_MAP,
Expand All @@ -25,7 +16,7 @@
TooManyRedirects,
map_exceptions,
)
from ._models import URL, Cookies, Headers, QueryParams, Request, Response
from ._models import Cookies, Headers, QueryParams, Request, Response, URL
from ._status_codes import codes
from ._transports.asgi import ASGITransport
from ._transports.wsgi import WSGITransport
Expand Down Expand Up @@ -100,9 +91,18 @@ def _get_proxy_map(
return {}
if isinstance(proxies, dict):
new_proxies = {}
filtered_proxy_keys = {"all", "http", "https"}
wrong_proxy_schemes = []
for key, value in proxies.items():
if key in filtered_proxy_keys:
wrong_proxy_schemes.append(key)
proxy = Proxy(url=value) if isinstance(value, (str, URL)) else value
new_proxies[str(key)] = proxy

if wrong_proxy_schemes:
valid_proxies = (f"{prefix}://" for prefix in wrong_proxy_schemes)
logger.warning(f"You should use proxy schemes like {', '.join(valid_proxies)} "
f"instead of using {', '.join(wrong_proxy_schemes)}")
return new_proxies
else:
proxy = Proxy(url=proxies) if isinstance(proxies, (str, URL)) else proxies
Expand Down Expand Up @@ -485,22 +485,25 @@ def __init__(
app=app,
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: 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,
)
for key, proxy in proxy_map.items()
}
self._proxies = dict(sorted(self._proxies.items()))
] = dict(sorted(proxies))

def _init_transport(
self,
Expand Down

0 comments on commit 8e02fce

Please sign in to comment.