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 b4b0b65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='http_request_recorder',
version='1.0.2',
version='1.0.3',
description='A package to record an respond to http requests, primarily for use in black box testing.',
long_description=readme,
author='',
Expand All @@ -21,7 +21,7 @@
packages=['http_request_recorder'],
package_data={"http_request_recorder": ["py.typed"]},
install_requires=[
'aiohttp~=3.9.5',
'aiohttp~=3.10.10',
],
zip_safe=False
)
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 b4b0b65

Please sign in to comment.