Fix iter_bytes with empty content (#1827)
This commit is contained in:
parent
06498df528
commit
10b60d47c7
@ -1488,7 +1488,7 @@ class Response:
|
||||
"""
|
||||
if hasattr(self, "_content"):
|
||||
chunk_size = len(self._content) if chunk_size is None else chunk_size
|
||||
for i in range(0, len(self._content), chunk_size):
|
||||
for i in range(0, len(self._content), max(chunk_size, 1)):
|
||||
yield self._content[i : i + chunk_size]
|
||||
else:
|
||||
decoder = self._get_content_decoder()
|
||||
@ -1586,7 +1586,7 @@ class Response:
|
||||
"""
|
||||
if hasattr(self, "_content"):
|
||||
chunk_size = len(self._content) if chunk_size is None else chunk_size
|
||||
for i in range(0, len(self._content), chunk_size):
|
||||
for i in range(0, len(self._content), max(chunk_size, 1)):
|
||||
yield self._content[i : i + chunk_size]
|
||||
else:
|
||||
decoder = self._get_content_decoder()
|
||||
|
||||
@ -486,6 +486,12 @@ def test_iter_bytes_with_chunk_size():
|
||||
assert parts == [b"Hello, world!"]
|
||||
|
||||
|
||||
def test_iter_bytes_with_empty_response():
|
||||
response = httpx.Response(200, content=b"")
|
||||
parts = [part for part in response.iter_bytes()]
|
||||
assert parts == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_aiter_bytes():
|
||||
response = httpx.Response(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user