Skip to content

Commit 01f1788

Browse files
committed
not always h1
1 parent d53a66e commit 01f1788

6 files changed

Lines changed: 30 additions & 10 deletions

File tree

httpcore/_async/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ async def _connect(self, request: Request) -> AsyncNetworkStream:
143143
if self._ssl_context is None
144144
else self._ssl_context
145145
)
146-
alpn_protocols = ["h2", "http/1.1"] if self._http2 else ["http/1.1"]
146+
alpn_protocols = []
147+
if self._http2:
148+
alpn_protocols.append("h2")
149+
if self._http1:
150+
alpn_protocols.append("http/1.1")
147151
ssl_context.set_alpn_protocols(alpn_protocols)
148152

149153
kwargs = {

httpcore/_async/http_proxy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ async def handle_async_request(self, request: Request) -> Response:
304304
if self._ssl_context is None
305305
else self._ssl_context
306306
)
307-
alpn_protocols = ["h2", "http/1.1"] if self._http2 else ["http/1.1"]
307+
alpn_protocols = []
308+
if self._http2:
309+
alpn_protocols.append("h2")
310+
if self._http1:
311+
alpn_protocols.append("http/1.1")
308312
ssl_context.set_alpn_protocols(alpn_protocols)
309313

310314
kwargs = {

httpcore/_async/socks_proxy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ async def handle_async_request(self, request: Request) -> Response:
251251
if self._ssl_context is None
252252
else self._ssl_context
253253
)
254-
alpn_protocols = (
255-
["h2", "http/1.1"] if self._http2 else ["http/1.1"]
256-
)
254+
alpn_protocols = []
255+
if self._http2:
256+
alpn_protocols.append("h2")
257+
if self._http1:
258+
alpn_protocols.append("http/1.1")
257259
ssl_context.set_alpn_protocols(alpn_protocols)
258260

259261
kwargs = {

httpcore/_sync/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ def _connect(self, request: Request) -> NetworkStream:
143143
if self._ssl_context is None
144144
else self._ssl_context
145145
)
146-
alpn_protocols = ["h2", "http/1.1"] if self._http2 else ["http/1.1"]
146+
alpn_protocols = []
147+
if self._http2:
148+
alpn_protocols.append("h2")
149+
if self._http1:
150+
alpn_protocols.append("http/1.1")
147151
ssl_context.set_alpn_protocols(alpn_protocols)
148152

149153
kwargs = {

httpcore/_sync/http_proxy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ def handle_request(self, request: Request) -> Response:
304304
if self._ssl_context is None
305305
else self._ssl_context
306306
)
307-
alpn_protocols = ["h2", "http/1.1"] if self._http2 else ["http/1.1"]
307+
alpn_protocols = []
308+
if self._http2:
309+
alpn_protocols.append("h2")
310+
if self._http1:
311+
alpn_protocols.append("http/1.1")
308312
ssl_context.set_alpn_protocols(alpn_protocols)
309313

310314
kwargs = {

httpcore/_sync/socks_proxy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ def handle_request(self, request: Request) -> Response:
251251
if self._ssl_context is None
252252
else self._ssl_context
253253
)
254-
alpn_protocols = (
255-
["h2", "http/1.1"] if self._http2 else ["http/1.1"]
256-
)
254+
alpn_protocols = []
255+
if self._http2:
256+
alpn_protocols.append("h2")
257+
if self._http1:
258+
alpn_protocols.append("http/1.1")
257259
ssl_context.set_alpn_protocols(alpn_protocols)
258260

259261
kwargs = {

0 commit comments

Comments
 (0)