diff --git a/httpx/_client.py b/httpx/_client.py index 11c8e12351..6078775523 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -580,6 +580,10 @@ class Client(BaseClient): to authenticate the client. Either a path to an SSL certificate file, or two-tuple of (certificate file, key file), or a three-tuple of (certificate file, key file, password). + * **http1** - *(optional)* A boolean indicating if HTTP/1 support should be + enabled. Defaults to `True`. + * **http2** - *(optional)* A boolean indicating if HTTP/2 support should be + enabled. Default to `False`. * **proxies** - *(optional)* A dictionary mapping proxy keys to proxy URLs. * **timeout** - *(optional)* The timeout configuration to use when sending @@ -1277,6 +1281,8 @@ class AsyncClient(BaseClient): to authenticate the client. Either a path to an SSL certificate file, or two-tuple of (certificate file, key file), or a three-tuple of (certificate file, key file, password). + * **http1** - *(optional)* A boolean indicating if HTTP/1 support should be + enabled. Defaults to `True`. * **http2** - *(optional)* A boolean indicating if HTTP/2 support should be enabled. Defaults to `False`. * **proxies** - *(optional)* A dictionary mapping HTTP protocols to proxy @@ -1412,6 +1418,7 @@ def _init_proxy_transport( return AsyncHTTPTransport( verify=verify, cert=cert, + http1=http1, http2=http2, limits=limits, trust_env=trust_env, diff --git a/httpx/_config.py b/httpx/_config.py index 837519afb5..3297342252 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -319,7 +319,8 @@ def __repr__(self) -> str: class Proxy: def __init__( - self, url: URLTypes, *, headers: HeaderTypes = None, mode: str = "DEFAULT" + self, url: URLTypes, *, headers: HeaderTypes = None, mode: str = "DEFAULT", + http1_override: typing.Optional[bool] = None, http2_override: typing.Optional[bool] = None ): url = URL(url) headers = Headers(headers) @@ -341,6 +342,18 @@ def __init__( self.url = url self.headers = headers self.mode = mode + self._http1_override = http1_override + self._http2_override = http2_override + + def http1_support(self, default: bool) -> bool: + if self._http1_override is not None: + return self._http1_override + return default + + def http2_support(self, default: bool) -> bool: + if self._http2_override is not None: + return self._http2_override + return default def _build_auth_header(self, username: str, password: str) -> str: userpass = (username.encode("utf-8"), password.encode("utf-8")) diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py index ae6c2d1777..25c2c658da 100644 --- a/httpx/_transports/default.py +++ b/httpx/_transports/default.py @@ -150,7 +150,8 @@ def __init__( max_connections=limits.max_connections, max_keepalive_connections=limits.max_keepalive_connections, keepalive_expiry=limits.keepalive_expiry, - http2=http2, + http1=proxy.http1_support(http1), + http2=proxy.http2_support(http2), backend=backend, ) @@ -247,7 +248,8 @@ def __init__( max_connections=limits.max_connections, max_keepalive_connections=limits.max_keepalive_connections, keepalive_expiry=limits.keepalive_expiry, - http2=http2, + http1=proxy.http1_support(http1), + http2=proxy.http2_support(http2), backend=backend, )