Commit 12f4470
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 <[email protected]>1 parent 94d04e0 commit 12f4470
File tree
2 files changed
+3
-3
lines changed- google/auth/transport
- tests_async/transport
2 files changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
0 commit comments