Skip to content
Myr

Fix iter_bytes with empty content (#1827)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by GitHub · parent 06498df · Browse files · 2 files+8 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−2 removed

  • tests:+6 added−0 removed
  • other:+2 added−2 removed

2 files+8 added−2 removed

modified:httpx/_models.py+2 added-2 removed
1486 unmodified lines
1487 This allows us to handle gzip, deflate, and brotli encoded responses.1488 """1489 if hasattr(self, "_content"):1490 chunk_size = len(self._content) if chunk_size is None else chunk_size1491 for i in range(0, len(self._content), chunk_size):1491 for i in range(0, len(self._content), max(chunk_size, 1)):1492 yield self._content[i : i + chunk_size]1493 else:1494 decoder = self._get_content_decoder()1495 chunker = ByteChunker(chunk_size=chunk_size)
89 unmodified lines
1585 This allows us to handle gzip, deflate, and brotli encoded responses.1586 """1587 if hasattr(self, "_content"):1588 chunk_size = len(self._content) if chunk_size is None else chunk_size1589 for i in range(0, len(self._content), chunk_size):1589 for i in range(0, len(self._content), max(chunk_size, 1)):1590 yield self._content[i : i + chunk_size]1591 else:1592 decoder = self._get_content_decoder()1593 chunker = ByteChunker(chunk_size=chunk_size)
269 unmodified lines
modified:tests/models/test_responses.py+6 added
484 unmodified lines
485 parts = [part for part in response.iter_bytes(chunk_size=20)]486 assert parts == [b"Hello, world!"]487488489def test_iter_bytes_with_empty_response():490 response = httpx.Response(200, content=b"")491 parts = [part for part in response.iter_bytes()]492 assert parts == []493494495@pytest.mark.asyncio496async def test_aiter_bytes():497 response = httpx.Response(498 200,
412 unmodified lines