remove unspecified condition, skip handle the chunk on zero bytes received

This commit is contained in:
yggverse 2025-02-09 02:02:55 +02:00
parent 62f53304aa
commit bb8c2273d4

View file

@ -55,9 +55,16 @@ pub fn for_memory_input_stream_async(
Ok(bytes) => {
let len = bytes.len(); // calculate once
// is the end of stream
if len == 0 {
return on_complete(Ok((memory_input_stream, total)));
}
// handle the chunk
total += len;
on_chunk(len, total);
// push bytes into the memory pool
memory_input_stream.add_bytes(&bytes);
// prevent memory overflow on size `limit` reached
@ -67,13 +74,6 @@ pub fn for_memory_input_stream_async(
return on_complete(Err(Error::BytesTotal(memory_input_stream, total, limit)));
}
// is the next iteration required?
if len < chunk // some servers may close the connection after first chunk request (@TODO this condition wants review)
|| len == 0
{
return on_complete(Ok((memory_input_stream, total)));
}
// continue reading..
for_memory_input_stream_async(
memory_input_stream,