diff --git a/src/httpcore2/httpcore2/_async/http2.py b/src/httpcore2/httpcore2/_async/http2.py index 0022a2b6..6f009c13 100644 --- a/src/httpcore2/httpcore2/_async/http2.py +++ b/src/httpcore2/httpcore2/_async/http2.py @@ -246,10 +246,11 @@ async def _send_stream_data(self, request: Request, stream_id: int, data: bytes) """ Send a single chunk of data in one or more data frames. """ - while data: + position = 0 + while position < len(data): max_flow = await self._wait_for_outgoing_flow(request, stream_id) - chunk_size = min(len(data), max_flow) - chunk, data = data[:chunk_size], data[chunk_size:] + chunk = data[position : position + max_flow] + position += len(chunk) self._h2_state.send_data(stream_id, chunk) await self._write_outgoing_data(request) diff --git a/src/httpcore2/httpcore2/_sync/http2.py b/src/httpcore2/httpcore2/_sync/http2.py index 3b79af8c..ee314c8a 100644 --- a/src/httpcore2/httpcore2/_sync/http2.py +++ b/src/httpcore2/httpcore2/_sync/http2.py @@ -246,10 +246,11 @@ def _send_stream_data(self, request: Request, stream_id: int, data: bytes) -> No """ Send a single chunk of data in one or more data frames. """ - while data: + position = 0 + while position < len(data): max_flow = self._wait_for_outgoing_flow(request, stream_id) - chunk_size = min(len(data), max_flow) - chunk, data = data[:chunk_size], data[chunk_size:] + chunk = data[position : position + max_flow] + position += len(chunk) self._h2_state.send_data(stream_id, chunk) self._write_outgoing_data(request)