From 8c36b51e479bf2eec5ad71043c07232dc26d1582 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 19 Nov 2024 12:28:07 -0600 Subject: [PATCH] Restore the ``force_close`` method to the ``ResponseHandler`` (#9997) --- CHANGES/9997.bugfix.rst | 1 + aiohttp/client_proto.py | 3 +++ tests/test_client_proto.py | 11 +++++++++++ 3 files changed, 15 insertions(+) create mode 100644 CHANGES/9997.bugfix.rst 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()