From: bli74 Date: Tue, 11 May 2021 09:40:46 +0000 (+0200) Subject: Support HTTP/2 prior-knowledge, using `httpx.Client(http1=False, http2=True)`. (... X-Git-Tag: 0.18.2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b17671f155aa857fb52911d94357147ba2a3ea4;p=thirdparty%2Fhttpx.git Support HTTP/2 prior-knowledge, using `httpx.Client(http1=False, http2=True)`. (#1624) * Pass flag http1 to httpcore. * Update httpcore version, reorder parameter list Co-authored-by: ebertli Co-authored-by: Tom Christie --- diff --git a/httpx/_client.py b/httpx/_client.py index 7fcc85b0..11c8e123 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -606,6 +606,7 @@ class Client(BaseClient): cookies: CookieTypes = None, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, proxies: ProxiesTypes = None, mounts: typing.Mapping[str, BaseTransport] = None, @@ -645,6 +646,7 @@ class Client(BaseClient): self._transport = self._init_transport( verify=verify, cert=cert, + http1=http1, http2=http2, limits=limits, transport=transport, @@ -658,6 +660,7 @@ class Client(BaseClient): proxy, verify=verify, cert=cert, + http1=http1, http2=http2, limits=limits, trust_env=trust_env, @@ -675,6 +678,7 @@ class Client(BaseClient): self, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, transport: BaseTransport = None, @@ -688,7 +692,12 @@ class Client(BaseClient): return WSGITransport(app=app) return HTTPTransport( - verify=verify, cert=cert, http2=http2, limits=limits, trust_env=trust_env + verify=verify, + cert=cert, + http1=http1, + http2=http2, + limits=limits, + trust_env=trust_env, ) def _init_proxy_transport( @@ -696,6 +705,7 @@ class Client(BaseClient): proxy: Proxy, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, trust_env: bool = True, @@ -703,6 +713,7 @@ class Client(BaseClient): return HTTPTransport( verify=verify, cert=cert, + http1=http1, http2=http2, limits=limits, trust_env=trust_env, @@ -1294,6 +1305,7 @@ class AsyncClient(BaseClient): cookies: CookieTypes = None, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, proxies: ProxiesTypes = None, mounts: typing.Mapping[str, AsyncBaseTransport] = None, @@ -1333,6 +1345,7 @@ class AsyncClient(BaseClient): self._transport = self._init_transport( verify=verify, cert=cert, + http1=http1, http2=http2, limits=limits, transport=transport, @@ -1347,6 +1360,7 @@ class AsyncClient(BaseClient): proxy, verify=verify, cert=cert, + http1=http1, http2=http2, limits=limits, trust_env=trust_env, @@ -1363,6 +1377,7 @@ class AsyncClient(BaseClient): self, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, transport: AsyncBaseTransport = None, @@ -1376,7 +1391,12 @@ class AsyncClient(BaseClient): return ASGITransport(app=app) return AsyncHTTPTransport( - verify=verify, cert=cert, http2=http2, limits=limits, trust_env=trust_env + verify=verify, + cert=cert, + http1=http1, + http2=http2, + limits=limits, + trust_env=trust_env, ) def _init_proxy_transport( @@ -1384,6 +1404,7 @@ class AsyncClient(BaseClient): proxy: Proxy, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, trust_env: bool = True, diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py index 1e58b529..ae6c2d17 100644 --- a/httpx/_transports/default.py +++ b/httpx/_transports/default.py @@ -116,6 +116,7 @@ class HTTPTransport(BaseTransport): self, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, trust_env: bool = True, @@ -133,6 +134,7 @@ class HTTPTransport(BaseTransport): max_connections=limits.max_connections, max_keepalive_connections=limits.max_keepalive_connections, keepalive_expiry=limits.keepalive_expiry, + http1=http1, http2=http2, uds=uds, local_address=local_address, @@ -211,6 +213,7 @@ class AsyncHTTPTransport(AsyncBaseTransport): self, verify: VerifyTypes = True, cert: CertTypes = None, + http1: bool = True, http2: bool = False, limits: Limits = DEFAULT_LIMITS, trust_env: bool = True, @@ -228,6 +231,7 @@ class AsyncHTTPTransport(AsyncBaseTransport): max_connections=limits.max_connections, max_keepalive_connections=limits.max_keepalive_connections, keepalive_expiry=limits.keepalive_expiry, + http1=http1, http2=http2, uds=uds, local_address=local_address, diff --git a/setup.py b/setup.py index e27cda8e..f3ada86f 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ setup( "certifi", "sniffio", "rfc3986[idna2008]>=1.3,<2", - "httpcore>=0.13.0,<0.14.0", + "httpcore>=0.13.3,<0.14.0", "async_generator; python_version < '3.7'" ], extras_require={