Repository navigation
Response iterators handle non-positive chunk sizes inconsistently #3880
Replies: 1 comment
|
Your reading of current The two paths really do disagree:
Rejecting |
|
Your reading of current The two paths really do disagree:
Rejecting |
Uh oh!
There was an error while loading. Please reload this page.
Summary
Responseiterators handlechunk_size=0and negative sizes differently depending on whether content is buffered or streamed. A bufferediter_bytes(0)can yield empty chunks. A streamediter_bytes(0)raises an internalValueError, whileiter_bytes(-1)raisesIndexErrorafter marking the response stream as consumed.Reproduction
Tested on Windows 11, Python 3.13.7, HTTPX
masterate347fb5e93b91f7cf63a575f595f33db8d90fe20(httpx 0.29.0,httpcore 1.0.9). This uses an in-memory response, so no HTTP server or protocol version is involved.On the unmodified commit, buffered
iter_bytes(0)yields empty chunks; streaming with zero raisesValueError: range() arg 3 must not be zero, and streaming with-1raisesIndexError: list index out of range. The failed streaming call leavesis_stream_consumed=True, so retrying with a valid size raisesStreamConsumed.Proposed fix
Reject non-positive sizes with a clear
ValueErrorbefore consuming a response stream. I have a small patch with regression tests covering sync and async byte, text, and raw iterators, including buffered byte content and retry after the invalid call.python -m pytest tests/models/test_responses.py -qpasses (130 tests), and Ruff passes on the changed files. I am opening the discussion first as requested by the contribution guide.All reactions