diff --git a/CHANGES/9052.bugfix.rst b/CHANGES/9052.bugfix.rst new file mode 100644 index 00000000000..913288d3368 --- /dev/null +++ b/CHANGES/9052.bugfix.rst @@ -0,0 +1 @@ +Fixed exception information getting lost on ``HttpProcessingError`` -- by :user:`Dreamsorcerer`. diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index 6765aaf0eba..ae621bc5d58 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -282,7 +282,15 @@ def data_received(self, data: bytes) -> None: # closed in this case self.transport.close() # should_close is True after the call - self.set_exception(HttpProcessingError(), underlying_exc) + if isinstance(underlying_exc, HttpProcessingError): + exc = HttpProcessingError( + code=underlying_exc.code, + message=underlying_exc.message, + headers=underlying_exc.headers, + ) + else: + exc = HttpProcessingError() + self.set_exception(exc, underlying_exc) return self._upgraded = upgraded diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index 8713f3682f7..437936e97b8 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -4021,10 +4021,6 @@ async def handler(_: web.Request) -> web.Response: await session.get("/") -@pytest.mark.xfail( - reason="#8395 Error message regression for large headers in 3.9.4", - raises=AssertionError, -) async def test_header_too_large_error(aiohttp_client: AiohttpClient) -> None: """By default when not specifying `max_field_size` requests should fail with a 400 status code."""