mirror of
https://github.com/actix/actix-website
synced 2025-01-22 16:15:56 +01:00
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.
This commit is contained in:
parent
845ab78512
commit
b43bbd2b51
@ -5,10 +5,11 @@ use futures::StreamExt;
|
|||||||
async fn index(mut body: web::Payload) -> Result<HttpResponse, Error> {
|
async fn index(mut body: web::Payload) -> Result<HttpResponse, Error> {
|
||||||
let mut bytes = web::BytesMut::new();
|
let mut bytes = web::BytesMut::new();
|
||||||
while let Some(item) = body.next().await {
|
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())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
// </streaming>
|
// </streaming>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user