Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 12f4470

Browse filesBrowse files
fix: use .read() instead of .content.read() in aiohttp transport (#1899)
Fixes issue where response content is empty when using `aiohttp-client-cache` by using `response.read()` instead of `response.content.read()`. **Rationale:** In `aiohttp`, `.read()` is the standard, high-level method for reading the full response body. It correctly handles internal state (like caching the body for subsequent calls), which is essential for compatibility with wrappers like `aiohttp-client-cache`. Accessing `.content.read()` directly bypasses this logic, leading to empty responses when the stream has already been consumed or intercepted by the caching layer. **Benefits:** - **Robustness:** Ensures correct behavior when `google-auth` is used in conjunction with `aiohttp` wrappers or middleware. - **Standards:** Aligns with `aiohttp` best practices for consuming response bodies. **Risk Mitigation:** - **Behavior:** `_CombinedResponse` is designed to load the full response into memory. Changing to `.read()` preserves this behavior exactly; it just uses a safer accessor. - **Performance:** Since `aiohttp`'s `.read()` returns a reference to the bytes, there is no additional memory overhead compared to the previous implementation. - **Internal:** This change is internal to the transport adapter and does not alter the public API or behavior for users not using caching libraries. --- *PR created automatically by Jules for task [3355868403646689815](https://jules.google.com/task/3355868403646689815) started by @chalmerlowe* --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Chalmer Lowe <chalmerlowe@google.com>
1 parent 94d04e0 commit 12f4470
Copy full SHA for 12f4470

2 files changed

+3-3Lines changed: 3 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎google/auth/transport/_aiohttp_requests.py‎

Copy file name to clipboardExpand all lines: google/auth/transport/_aiohttp_requests.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def data(self):
7979

8080
async def raw_content(self):
8181
if self._raw_content is None:
82-
self._raw_content = await self._response.content.read()
82+
self._raw_content = await self._response.read()
8383
return self._raw_content
8484

8585
async def content(self):
Collapse file

‎tests_async/transport/test_aiohttp_requests.py‎

Copy file name to clipboardExpand all lines: tests_async/transport/test_aiohttp_requests.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test__is_compressed_not(self):
4040
@pytest.mark.asyncio
4141
async def test_raw_content(self):
4242
mock_response = mock.AsyncMock()
43-
mock_response.content.read.return_value = mock.sentinel.read
43+
mock_response.read.return_value = mock.sentinel.read
4444
combined_response = aiohttp_requests._CombinedResponse(response=mock_response)
4545
raw_content = await combined_response.raw_content()
4646
assert raw_content == mock.sentinel.read
@@ -53,7 +53,7 @@ async def test_raw_content(self):
5353
@pytest.mark.asyncio
5454
async def test_content(self):
5555
mock_response = mock.AsyncMock()
56-
mock_response.content.read.return_value = mock.sentinel.read
56+
mock_response.read.return_value = mock.sentinel.read
5757
combined_response = aiohttp_requests._CombinedResponse(response=mock_response)
5858
content = await combined_response.content()
5959
assert content == mock.sentinel.read

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.