save
This commit is contained in:
parent
1427f37b1c
commit
e026ff4bbb
63
src/main.rs
63
src/main.rs
|
@ -25,7 +25,7 @@ use actix_web::http::{header, StatusCode};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{Read, BufRead, Write, ErrorKind};
|
use std::io::{Read, BufRead, Write, ErrorKind};
|
||||||
use futures::{Stream, StreamExt, TryStreamExt, future, stream, TryFutureExt};
|
use futures::{Stream, StreamExt, TryStreamExt, future, stream, TryFutureExt, pin_mut};
|
||||||
use actix_web::web::{Buf, Bytes};
|
use actix_web::web::{Buf, Bytes};
|
||||||
use actix_web::http::header::IntoHeaderValue;
|
use actix_web::http::header::IntoHeaderValue;
|
||||||
|
|
||||||
|
@ -243,31 +243,48 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
|
||||||
//let mut body = Vec::new();
|
//let mut body = Vec::new();
|
||||||
//rdr.bytes()
|
//rdr.bytes()
|
||||||
|
|
||||||
let response = builder.streaming(stream::try_unfold(0, |_useless| async move {
|
// let stream = stream::try_unfold(0, |state| async move {
|
||||||
let mut buff : [u8; 1024] = [0; 1024];
|
//
|
||||||
rdr.read(&mut buff[..]).await.map(|l| {
|
// if state <= 2 {
|
||||||
print!("{}", String::from_utf8_lossy(&buff[0..l]));
|
// let next_state = state + 1;
|
||||||
Some(Bytes::copy_from_slice(&buff[0..l]))
|
// let yielded = state * 2;
|
||||||
});
|
// Ok(Some((yielded, next_state)))
|
||||||
})
|
// } else {
|
||||||
);
|
// Ok(None)
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
let response = builder.streaming(stream::repeat_with(move || {
|
let unfold = stream::try_unfold(0, |_useless| async move {
|
||||||
let mut buff : [u8; 1024] = [0; 1024];
|
let mut buff: [u8; 1024] = [0; 1024];
|
||||||
match rdr.read(&mut buff[..]) {
|
let result = rdr.read(&mut buff[..]).await;
|
||||||
Ok(l) => {
|
match result {
|
||||||
print!("{}", String::from_utf8_lossy(&buff[0..l]));
|
Ok(l) => {Ok(Some((Bytes::copy_from_slice(&buff[0..l]), 0)))}
|
||||||
Ok(Bytes::copy_from_slice(&buff[0..l])) }
|
|
||||||
Err(e) => {Err(e)}
|
Err(e) => {Err(e)}
|
||||||
}
|
}
|
||||||
})
|
// result.map(|l| {
|
||||||
.take_while(|bytes| {
|
// print!("{}", String::from_utf8_lossy(&buff[0..l]));
|
||||||
match bytes {
|
// Some((Bytes::copy_from_slice(&buff[0..l]), 0))
|
||||||
Ok(bytes) => {future::ready(bytes.len() != 0)}
|
// });
|
||||||
Err(_) => {future::ready(false)}
|
});
|
||||||
}
|
pin_mut!(unfold);
|
||||||
})
|
let response = builder.streaming(unfold);
|
||||||
);
|
|
||||||
|
// let response = builder.streaming(stream::repeat_with(move || {
|
||||||
|
// let mut buff : [u8; 1024] = [0; 1024];
|
||||||
|
// match rdr.read(&mut buff[..]) {
|
||||||
|
// 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| {
|
||||||
|
// match bytes {
|
||||||
|
// Ok(bytes) => {future::ready(bytes.len() != 0)}
|
||||||
|
// Err(_) => {future::ready(false)}
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// );
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue