From b43bbd2b510780d0831b3b22c51e578621e7e7eb Mon Sep 17 00:00:00 2001 From: Daniel Franklin Date: Sun, 1 Mar 2020 15:18:22 -0500 Subject: [PATCH] Fix logic bug in streaming request example Previously the example printed "Chunk: {}" once after the entire response was received, but the accompanying text read "we read and print the request payload chunk by chunk". The example now prints every chunk as it was received. --- examples/requests/src/streaming.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/requests/src/streaming.rs b/examples/requests/src/streaming.rs index c59cc6e..414d34f 100644 --- a/examples/requests/src/streaming.rs +++ b/examples/requests/src/streaming.rs @@ -5,10 +5,11 @@ use futures::StreamExt; async fn index(mut body: web::Payload) -> Result { let mut bytes = web::BytesMut::new(); while let Some(item) = body.next().await { - bytes.extend_from_slice(&item?); + let item = item?; + println!("Chunk: {:?}", &item); + bytes.extend_from_slice(&item); } - println!("Chunk: {:?}", bytes); Ok(HttpResponse::Ok().finish()) } //