Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion httpcore/_async/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 5 additions & 1 deletion httpcore/_async/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 5 additions & 3 deletions httpcore/_async/socks_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 5 additions & 1 deletion httpcore/_sync/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 5 additions & 1 deletion httpcore/_sync/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 5 additions & 3 deletions httpcore/_sync/socks_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 2 additions & 0 deletions tests/_async/test_socks_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions tests/_sync/test_socks_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down