From 4f3735d559f5fc9ec705f9d05f4d59708e4b8701 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Thu, 1 Aug 2024 15:30:31 +0200 Subject: [PATCH 1/6] Add public response property to ClientWebsocketResponse --- aiohttp/client_ws.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aiohttp/client_ws.py b/aiohttp/client_ws.py index 28d1117502f..4aafad475f7 100644 --- a/aiohttp/client_ws.py +++ b/aiohttp/client_ws.py @@ -155,6 +155,10 @@ def compress(self) -> int: def client_notakeover(self) -> bool: return self._client_notakeover + @property + def response(self) -> ClientResponse: + return self._response + def get_extra_info(self, name: str, default: Any = None) -> Any: """extra info from connection transport""" conn = self._response.connection From 2875107edd2bd4bedac79b93c02cc50444f275c4 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Thu, 1 Aug 2024 15:48:29 +0200 Subject: [PATCH 2/6] Adding attribute in client reference documentation --- docs/client_reference.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/client_reference.rst b/docs/client_reference.rst index d5092692b7e..794b64c69cb 100644 --- a/docs/client_reference.rst +++ b/docs/client_reference.rst @@ -1525,6 +1525,13 @@ manually. May be ``None`` if server and client protocols are not overlapping. + .. attribute:: response + + The :class:`ClientResponse ` response object. + Can be used to get the response headers and cookies. + + .. versionadded:: 4.0 + .. method:: get_extra_info(name, default=None) Reads optional extra information from the connection's transport. From c901a55fc26f39709490110a83379f29d2af141c Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Thu, 1 Aug 2024 16:03:26 +0200 Subject: [PATCH 3/6] Adding test --- tests/test_client_ws.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_client_ws.py b/tests/test_client_ws.py index 81ad41c2347..db21a2603d9 100644 --- a/tests/test_client_ws.py +++ b/tests/test_client_ws.py @@ -40,6 +40,9 @@ async def test_ws_connect(ws_key: Any, loop: Any, key_data: Any) -> None: assert res.protocol == "chat" assert hdrs.ORIGIN not in m_req.call_args[1]["headers"] + # Checking new response attribute + assert res.response.headers == resp.headers + async def test_ws_connect_read_timeout_is_reset_to_inf( ws_key: Any, loop: Any, key_data: Any From 4f72c035a7c5462d7f93cce2ac2a90fb2225d4e0 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Thu, 1 Aug 2024 16:17:02 +0200 Subject: [PATCH 4/6] Adding myself to CONTRIBUTORS.txt --- CONTRIBUTORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 3f4a257a678..ef97bbf2c39 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -213,6 +213,7 @@ Kyrylo Perevozchikov Kyungmin Lee Lars P. Søndergaard Lee LieWhite +Leszek Hanusz Liu Hua Louis-Philippe Huberdeau Loïc Lajeanne From 56b517eed680c398ccac416d2bed3e3e55bad0eb Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Thu, 1 Aug 2024 16:28:45 +0200 Subject: [PATCH 5/6] Adding CHANGES file --- CHANGES/8572.feature.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 CHANGES/8572.feature.rst diff --git a/CHANGES/8572.feature.rst b/CHANGES/8572.feature.rst new file mode 100644 index 00000000000..9d6f0c7ae41 --- /dev/null +++ b/CHANGES/8572.feature.rst @@ -0,0 +1,2 @@ +Added ``response`` attribute to the :class:`ClientWebSocketResponse ` class. It allows users to have access to response headers and cookies of a websocket request +-- by :user:`leszekhanusz`. From ab3bd20b03df3525f68158aeed4380995926b727 Mon Sep 17 00:00:00 2001 From: Leszek Hanusz Date: Thu, 1 Aug 2024 18:35:36 +0200 Subject: [PATCH 6/6] Fix class reference in CHANGES --- CHANGES/8572.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES/8572.feature.rst b/CHANGES/8572.feature.rst index 9d6f0c7ae41..28b7a7cfb26 100644 --- a/CHANGES/8572.feature.rst +++ b/CHANGES/8572.feature.rst @@ -1,2 +1,2 @@ -Added ``response`` attribute to the :class:`ClientWebSocketResponse ` class. It allows users to have access to response headers and cookies of a websocket request +Added ``response`` attribute to the :py:class:`~aiohttp.ClientWebSocketResponse` class. It allows users to have access to response headers and cookies of a websocket request -- by :user:`leszekhanusz`.