A byte-iterator over the decoded response content. This allows us to handle gzip, deflate, brotli, and zstd encoded responses.
(
self, chunk_size: int | None = None
)
| 980 | return self._content |
| 981 | |
| 982 | async def aiter_bytes( |
| 983 | self, chunk_size: int | None = None |
| 984 | ) -> typing.AsyncIterator[bytes]: |
| 985 | """ |
| 986 | A byte-iterator over the decoded response content. |
| 987 | This allows us to handle gzip, deflate, brotli, and zstd encoded responses. |
| 988 | """ |
| 989 | if hasattr(self, "_content"): |
| 990 | chunk_size = len(self._content) if chunk_size is None else chunk_size |
| 991 | for i in range(0, len(self._content), max(chunk_size, 1)): |
| 992 | yield self._content[i : i + chunk_size] |
| 993 | else: |
| 994 | decoder = self._get_content_decoder() |
| 995 | chunker = ByteChunker(chunk_size=chunk_size) |
| 996 | with request_context(request=self._request): |
| 997 | async for raw_bytes in self.aiter_raw(): |
| 998 | decoded = decoder.decode(raw_bytes) |
| 999 | for chunk in chunker.decode(decoded): |
| 1000 | yield chunk |
| 1001 | decoded = decoder.flush() |
| 1002 | for chunk in chunker.decode(decoded): |
| 1003 | yield chunk # pragma: no cover |
| 1004 | for chunk in chunker.flush(): |
| 1005 | yield chunk |
| 1006 | |
| 1007 | async def aiter_text( |
| 1008 | self, chunk_size: int | None = None |