From 81c9669e178cec9f78d29c258ab5f3cdbc8eb774 Mon Sep 17 00:00:00 2001 From: Hubert Date: Fri, 9 Jul 2021 07:05:18 +0200 Subject: [PATCH] fonctionne mais pose question (stop lorsque 0 et pourquoi pas d'envoie avant la fin) --- src/main.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 74c7d8d..8202621 100644 --- a/src/main.rs +++ b/src/main.rs @@ -206,15 +206,23 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa println!("Write body..."); //let mut body = Vec::new(); //rdr.bytes() - let response = builder.streaming(stream::repeat_with(|| { + let response = builder.streaming(stream::repeat_with(move || { let mut buff : [u8; 1024] = [0; 1024]; match rdr.read(&mut buff[..]) { - Ok(l) => {Ok(Bytes::copy_from_slice(&buff[0..l]))} + Ok(l) => { + print!("{}", String::from_utf8_lossy(&buff[0..l])); + Ok(Bytes::copy_from_slice(&buff[0..l])) } Err(e) => {Err(e)} } - }).take_while(|bytes| { - future::ready(bytes.is_ok()) - })); + }) + .take_while(|bytes| { + match bytes { + Ok(bytes) => {future::ready(bytes.len() != 0)} + Err(_) => {future::ready(false)} + } + // future::ready(bytes.is_ok()) + }) + ); //rdr.read_to_end(&mut body)?; // println!("{}", String::from_utf8(body.clone()).expect("bad utf8")); return Ok(response);