Skip to content

Commit

Permalink
fix: support http2 upgrade requests
Browse files Browse the repository at this point in the history
due to an issue in underlying aiohttp library, http2 upgrade requests
caused an internal error.

This was fixed in [#8252](aio-libs/aiohttp#8252)
and presumeably included in release 3.9.4, but included test shows, that
is only fixed for >= 3.10.2.

Co-authored-by: Andreas Schimmelschulze <[email protected]>
  • Loading branch information
paulschwoerer and andreas-sipgate committed Oct 22, 2024
1 parent 14982c2 commit 50716e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aiohttp~=3.9.5
aiohttp~=3.10.10
types-setuptools
pre-commit
20 changes: 20 additions & 0 deletions tests/test_http_request_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,23 @@ async def test_matches_on_headers(self) -> None:

recorded_foo_request = await foo_expect.wait()
self.assertEqual(recorded_foo_request, b'foo-data')

# aiohttp (< 3.10.2) has buggy behavior when dealing with http2 upgrade requests.
# This was fixed in https://github.com/aio-libs/aiohttp/pull/8252 which according
# to release notes is included in 3.9.4. However, first working version is 3.10.2.
async def test_connection_with_http2_upgrade_does_not_fail(self) -> None:
http2_upgrade_headers = {
'Connection': 'Upgrade, HTTP2-Settings',
'Upgrade': 'h2c',
'HTTP2-Settings': 'AAEAAEAAAAIAAAAAAAMAAAAAAAQBAAAAAAUAAEAAAAYABgAA'
}

async with (HttpRequestRecorder(name="testrecorder",
port=self.port) as recorder, ClientSession(headers=http2_upgrade_headers) as http_session):
exp = recorder.expect_path('/anypath', responses='anywhere')

response = await http_session.post(f'http://localhost:{self.port}/anypath', data='anything')

await exp.wait()

self.assertEqual(200, response.status)

0 comments on commit 50716e2

Please sign in to comment.