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 2c1fc6af3ef..b899908d786 100644 --- a/aiohttp/client_proto.py +++ b/aiohttp/client_proto.py @@ -60,6 +60,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 ba45d6a6839..a70dc62e135 100644 --- a/tests/test_client_proto.py +++ b/tests/test_client_proto.py @@ -1,3 +1,4 @@ +import asyncio from unittest import mock from yarl import URL @@ -9,7 +10,18 @@ from aiohttp.helpers import TimerNoop -async def test_oserror(loop) -> None: +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() proto.connection_made(transport)