fonctionne mais pose question (stop lorsque 0 et pourquoi pas d'envoie avant la fin)

This commit is contained in:
Hubert 2021-07-09 07:05:18 +02:00
parent 3aa2c63346
commit 81c9669e17
1 changed files with 13 additions and 5 deletions

View File

@ -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);