Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Fixed

- HTTP/2 flag not being passed down to proxy connections.

## 0.8.2 (May 3rd, 2020)

### Fixed
Expand Down
8 changes: 5 additions & 3 deletions httpcore/_async/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def _forward_request(

if connection is None:
connection = AsyncHTTPConnection(
origin=origin, http2=False, ssl_context=self._ssl_context,
origin=origin, http2=self._http2, ssl_context=self._ssl_context,
)
await self._add_to_pool(connection)

Expand Down Expand Up @@ -133,7 +133,9 @@ async def _tunnel_request(
if connection is None:
# First, create a connection to the proxy server
proxy_connection = AsyncHTTPConnection(
origin=self.proxy_origin, http2=False, ssl_context=self._ssl_context,
origin=self.proxy_origin,
http2=self._http2,
ssl_context=self._ssl_context,
)

# Issue a CONNECT request...
Expand Down Expand Up @@ -169,7 +171,7 @@ async def _tunnel_request(
# retain the tunnel.
connection = AsyncHTTPConnection(
origin=origin,
http2=False,
http2=self._http2,
ssl_context=self._ssl_context,
socket=proxy_connection.socket,
)
Expand Down
8 changes: 5 additions & 3 deletions httpcore/_sync/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _forward_request(

if connection is None:
connection = SyncHTTPConnection(
origin=origin, http2=False, ssl_context=self._ssl_context,
origin=origin, http2=self._http2, ssl_context=self._ssl_context,
)
self._add_to_pool(connection)

Expand Down Expand Up @@ -133,7 +133,9 @@ def _tunnel_request(
if connection is None:
# First, create a connection to the proxy server
proxy_connection = SyncHTTPConnection(
origin=self.proxy_origin, http2=False, ssl_context=self._ssl_context,
origin=self.proxy_origin,
http2=self._http2,
ssl_context=self._ssl_context,
)

# Issue a CONNECT request...
Expand Down Expand Up @@ -169,7 +171,7 @@ def _tunnel_request(
# retain the tunnel.
connection = SyncHTTPConnection(
origin=origin,
http2=False,
http2=self._http2,
ssl_context=self._ssl_context,
socket=proxy_connection.socket,
)
Expand Down
5 changes: 4 additions & 1 deletion tests/async_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ async def test_http_proxy(
# mitmproxy does not support forwarding HTTPS requests
@pytest.mark.parametrize("proxy_mode", ["DEFAULT", "TUNNEL_ONLY"])
@pytest.mark.usefixtures("async_environment")
@pytest.mark.parametrize("http2", [False, True])
async def test_proxy_https_requests(
proxy_server: typing.Tuple[bytes, bytes, int],
ca_ssl_context: ssl.SSLContext,
proxy_mode: str,
http2: bool,
) -> None:
method = b"GET"
url = (b"https", b"example.org", 443, b"/")
Expand All @@ -228,12 +230,13 @@ async def test_proxy_https_requests(
ssl_context=ca_ssl_context,
max_connections=max_connections,
max_keepalive=max_keepalive,
http2=http2,
) as http:
http_version, status_code, reason, headers, stream = await http.request(
method, url, headers
)
_ = await read_body(stream)

assert http_version == b"HTTP/1.1"
assert http_version == (b"HTTP/2" if http2 else b"HTTP/1.1")
assert status_code == 200
assert reason == b"OK"
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def cert_authority() -> trustme.CA:
return trustme.CA()


@pytest.fixture(scope="session")
@pytest.fixture()
def ca_ssl_context(cert_authority: trustme.CA) -> ssl.SSLContext:
ctx = ssl.create_default_context()
cert_authority.configure_trust(ctx)
Expand Down
5 changes: 4 additions & 1 deletion tests/sync_tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,12 @@ def test_http_proxy(
# mitmproxy does not support forwarding HTTPS requests
@pytest.mark.parametrize("proxy_mode", ["DEFAULT", "TUNNEL_ONLY"])

@pytest.mark.parametrize("http2", [False, True])
def test_proxy_https_requests(
proxy_server: typing.Tuple[bytes, bytes, int],
ca_ssl_context: ssl.SSLContext,
proxy_mode: str,
http2: bool,
) -> None:
method = b"GET"
url = (b"https", b"example.org", 443, b"/")
Expand All @@ -228,12 +230,13 @@ def test_proxy_https_requests(
ssl_context=ca_ssl_context,
max_connections=max_connections,
max_keepalive=max_keepalive,
http2=http2,
) as http:
http_version, status_code, reason, headers, stream = http.request(
method, url, headers
)
_ = read_body(stream)

assert http_version == b"HTTP/1.1"
assert http_version == (b"HTTP/2" if http2 else b"HTTP/1.1")
assert status_code == 200
assert reason == b"OK"