Skip to content

Commit 9b17671

Browse files
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 <bert.lindemann@ericsson.com> Co-authored-by: Tom Christie <tom@tomchristie.com>
1 parent 69409bb commit 9b17671

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

httpx/_client.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ def __init__(
606606
cookies: CookieTypes = None,
607607
verify: VerifyTypes = True,
608608
cert: CertTypes = None,
609+
http1: bool = True,
609610
http2: bool = False,
610611
proxies: ProxiesTypes = None,
611612
mounts: typing.Mapping[str, BaseTransport] = None,
@@ -645,6 +646,7 @@ def __init__(
645646
self._transport = self._init_transport(
646647
verify=verify,
647648
cert=cert,
649+
http1=http1,
648650
http2=http2,
649651
limits=limits,
650652
transport=transport,
@@ -658,6 +660,7 @@ def __init__(
658660
proxy,
659661
verify=verify,
660662
cert=cert,
663+
http1=http1,
661664
http2=http2,
662665
limits=limits,
663666
trust_env=trust_env,
@@ -675,6 +678,7 @@ def _init_transport(
675678
self,
676679
verify: VerifyTypes = True,
677680
cert: CertTypes = None,
681+
http1: bool = True,
678682
http2: bool = False,
679683
limits: Limits = DEFAULT_LIMITS,
680684
transport: BaseTransport = None,
@@ -688,21 +692,28 @@ def _init_transport(
688692
return WSGITransport(app=app)
689693

690694
return HTTPTransport(
691-
verify=verify, cert=cert, http2=http2, limits=limits, trust_env=trust_env
695+
verify=verify,
696+
cert=cert,
697+
http1=http1,
698+
http2=http2,
699+
limits=limits,
700+
trust_env=trust_env,
692701
)
693702

694703
def _init_proxy_transport(
695704
self,
696705
proxy: Proxy,
697706
verify: VerifyTypes = True,
698707
cert: CertTypes = None,
708+
http1: bool = True,
699709
http2: bool = False,
700710
limits: Limits = DEFAULT_LIMITS,
701711
trust_env: bool = True,
702712
) -> BaseTransport:
703713
return HTTPTransport(
704714
verify=verify,
705715
cert=cert,
716+
http1=http1,
706717
http2=http2,
707718
limits=limits,
708719
trust_env=trust_env,
@@ -1294,6 +1305,7 @@ def __init__(
12941305
cookies: CookieTypes = None,
12951306
verify: VerifyTypes = True,
12961307
cert: CertTypes = None,
1308+
http1: bool = True,
12971309
http2: bool = False,
12981310
proxies: ProxiesTypes = None,
12991311
mounts: typing.Mapping[str, AsyncBaseTransport] = None,
@@ -1333,6 +1345,7 @@ def __init__(
13331345
self._transport = self._init_transport(
13341346
verify=verify,
13351347
cert=cert,
1348+
http1=http1,
13361349
http2=http2,
13371350
limits=limits,
13381351
transport=transport,
@@ -1347,6 +1360,7 @@ def __init__(
13471360
proxy,
13481361
verify=verify,
13491362
cert=cert,
1363+
http1=http1,
13501364
http2=http2,
13511365
limits=limits,
13521366
trust_env=trust_env,
@@ -1363,6 +1377,7 @@ def _init_transport(
13631377
self,
13641378
verify: VerifyTypes = True,
13651379
cert: CertTypes = None,
1380+
http1: bool = True,
13661381
http2: bool = False,
13671382
limits: Limits = DEFAULT_LIMITS,
13681383
transport: AsyncBaseTransport = None,
@@ -1376,14 +1391,20 @@ def _init_transport(
13761391
return ASGITransport(app=app)
13771392

13781393
return AsyncHTTPTransport(
1379-
verify=verify, cert=cert, http2=http2, limits=limits, trust_env=trust_env
1394+
verify=verify,
1395+
cert=cert,
1396+
http1=http1,
1397+
http2=http2,
1398+
limits=limits,
1399+
trust_env=trust_env,
13801400
)
13811401

13821402
def _init_proxy_transport(
13831403
self,
13841404
proxy: Proxy,
13851405
verify: VerifyTypes = True,
13861406
cert: CertTypes = None,
1407+
http1: bool = True,
13871408
http2: bool = False,
13881409
limits: Limits = DEFAULT_LIMITS,
13891410
trust_env: bool = True,

httpx/_transports/default.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def __init__(
116116
self,
117117
verify: VerifyTypes = True,
118118
cert: CertTypes = None,
119+
http1: bool = True,
119120
http2: bool = False,
120121
limits: Limits = DEFAULT_LIMITS,
121122
trust_env: bool = True,
@@ -133,6 +134,7 @@ def __init__(
133134
max_connections=limits.max_connections,
134135
max_keepalive_connections=limits.max_keepalive_connections,
135136
keepalive_expiry=limits.keepalive_expiry,
137+
http1=http1,
136138
http2=http2,
137139
uds=uds,
138140
local_address=local_address,
@@ -211,6 +213,7 @@ def __init__(
211213
self,
212214
verify: VerifyTypes = True,
213215
cert: CertTypes = None,
216+
http1: bool = True,
214217
http2: bool = False,
215218
limits: Limits = DEFAULT_LIMITS,
216219
trust_env: bool = True,
@@ -228,6 +231,7 @@ def __init__(
228231
max_connections=limits.max_connections,
229232
max_keepalive_connections=limits.max_keepalive_connections,
230233
keepalive_expiry=limits.keepalive_expiry,
234+
http1=http1,
231235
http2=http2,
232236
uds=uds,
233237
local_address=local_address,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_packages(package):
5959
"certifi",
6060
"sniffio",
6161
"rfc3986[idna2008]>=1.3,<2",
62-
"httpcore>=0.13.0,<0.14.0",
62+
"httpcore>=0.13.3,<0.14.0",
6363
"async_generator; python_version < '3.7'"
6464
],
6565
extras_require={

0 commit comments

Comments
 (0)