diff --git a/CHANGES/9997.bugfix.rst b/CHANGES/9997.bugfix.rst new file mode 100644 index 00000000000..2081ab6855b --- /dev/null +++ b/CHANGES/9997.bugfix.rst @@ -0,0 +1 @@ +Restored the ``force_close`` method to the ``ResponseHandler`` -- by :user:`bdraco`. diff --git a/aiohttp/client_proto.py b/aiohttp/client_proto.py index 5fcc24c154d..006112bc6f4 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -64,6 +64,9 @@ def should_close(self) -> bool: or self._tail ) + def force_close(self) -> None: + self._should_close = True + def close(self) -> None: transport = self.transport if transport is not None: diff --git a/tests/test_client_proto.py b/tests/test_client_proto.py index 154fc1dea00..52065eca318 100644 --- a/tests/test_client_proto.py +++ b/tests/test_client_proto.py @@ -12,6 +12,17 @@ from aiohttp.http_parser import RawResponseMessage +async def test_force_close(loop: asyncio.AbstractEventLoop) -> None: + """Ensure that the force_close method sets the should_close attribute to True. + + This is used externally in aiodocker + https://github.com/aio-libs/aiodocker/issues/920 + """ + proto = ResponseHandler(loop=loop) + proto.force_close() + assert proto.should_close + + async def test_oserror(loop: asyncio.AbstractEventLoop) -> None: proto = ResponseHandler(loop=loop) transport = mock.Mock()