diff --git a/httpcore/_async/connection.py b/httpcore/_async/connection.py index b42581df..7894d0e0 100644 --- a/httpcore/_async/connection.py +++ b/httpcore/_async/connection.py @@ -143,7 +143,11 @@ async def _connect(self, request: Request) -> AsyncNetworkStream: if self._ssl_context is None else self._ssl_context ) - alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"] + alpn_protocols = [] + if self._http2: + alpn_protocols.append("h2") + if self._http1: + alpn_protocols.append("http/1.1") ssl_context.set_alpn_protocols(alpn_protocols) kwargs = { diff --git a/httpcore/_async/http_proxy.py b/httpcore/_async/http_proxy.py index cc9d9206..3b7c3c24 100644 --- a/httpcore/_async/http_proxy.py +++ b/httpcore/_async/http_proxy.py @@ -304,7 +304,11 @@ async def handle_async_request(self, request: Request) -> Response: if self._ssl_context is None else self._ssl_context ) - alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"] + alpn_protocols = [] + if self._http2: + alpn_protocols.append("h2") + if self._http1: + alpn_protocols.append("http/1.1") ssl_context.set_alpn_protocols(alpn_protocols) kwargs = { diff --git a/httpcore/_async/socks_proxy.py b/httpcore/_async/socks_proxy.py index b363f55a..1bd9c704 100644 --- a/httpcore/_async/socks_proxy.py +++ b/httpcore/_async/socks_proxy.py @@ -251,9 +251,11 @@ async def handle_async_request(self, request: Request) -> Response: if self._ssl_context is None else self._ssl_context ) - alpn_protocols = ( - ["http/1.1", "h2"] if self._http2 else ["http/1.1"] - ) + alpn_protocols = [] + if self._http2: + alpn_protocols.append("h2") + if self._http1: + alpn_protocols.append("http/1.1") ssl_context.set_alpn_protocols(alpn_protocols) kwargs = { diff --git a/httpcore/_sync/connection.py b/httpcore/_sync/connection.py index 363f8be8..d5d70212 100644 --- a/httpcore/_sync/connection.py +++ b/httpcore/_sync/connection.py @@ -143,7 +143,11 @@ def _connect(self, request: Request) -> NetworkStream: if self._ssl_context is None else self._ssl_context ) - alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"] + alpn_protocols = [] + if self._http2: + alpn_protocols.append("h2") + if self._http1: + alpn_protocols.append("http/1.1") ssl_context.set_alpn_protocols(alpn_protocols) kwargs = { diff --git a/httpcore/_sync/http_proxy.py b/httpcore/_sync/http_proxy.py index ecca88f7..fec02a53 100644 --- a/httpcore/_sync/http_proxy.py +++ b/httpcore/_sync/http_proxy.py @@ -304,7 +304,11 @@ def handle_request(self, request: Request) -> Response: if self._ssl_context is None else self._ssl_context ) - alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"] + alpn_protocols = [] + if self._http2: + alpn_protocols.append("h2") + if self._http1: + alpn_protocols.append("http/1.1") ssl_context.set_alpn_protocols(alpn_protocols) kwargs = { diff --git a/httpcore/_sync/socks_proxy.py b/httpcore/_sync/socks_proxy.py index 0ca96ddf..4195f4c3 100644 --- a/httpcore/_sync/socks_proxy.py +++ b/httpcore/_sync/socks_proxy.py @@ -251,9 +251,11 @@ def handle_request(self, request: Request) -> Response: if self._ssl_context is None else self._ssl_context ) - alpn_protocols = ( - ["http/1.1", "h2"] if self._http2 else ["http/1.1"] - ) + alpn_protocols = [] + if self._http2: + alpn_protocols.append("h2") + if self._http1: + alpn_protocols.append("http/1.1") ssl_context.set_alpn_protocols(alpn_protocols) kwargs = { diff --git a/tests/_async/test_socks_proxy.py b/tests/_async/test_socks_proxy.py index 907594a4..01e184e2 100644 --- a/tests/_async/test_socks_proxy.py +++ b/tests/_async/test_socks_proxy.py @@ -27,6 +27,8 @@ async def test_socks5_request(): async with httpcore.AsyncConnectionPool( proxy=httpcore.Proxy("socks5://localhost:8080/"), network_backend=network_backend, + # We also enable h2, but will negotiated http1.1 + http2=True, ) as proxy: # Sending an intial request, which once complete will return to the pool, IDLE. async with proxy.stream("GET", "https://example.com/") as response: diff --git a/tests/_sync/test_socks_proxy.py b/tests/_sync/test_socks_proxy.py index 89ec9fae..072cb3f9 100644 --- a/tests/_sync/test_socks_proxy.py +++ b/tests/_sync/test_socks_proxy.py @@ -27,6 +27,8 @@ def test_socks5_request(): with httpcore.ConnectionPool( proxy=httpcore.Proxy("socks5://localhost:8080/"), network_backend=network_backend, + # We also enable h2, but will negotiated http1.1 + http2=True, ) as proxy: # Sending an intial request, which once complete will return to the pool, IDLE. with proxy.stream("GET", "https://example.com/") as response: