Compare commits
2 Commits
1427f37b1c
...
b22b5f81c7
Author | SHA1 | Date |
---|---|---|
Hubert | b22b5f81c7 | |
Hubert | e026ff4bbb |
|
@ -17,4 +17,4 @@ askama_actix = "0.11.1"
|
||||||
env_logger = "0.8.4"
|
env_logger = "0.8.4"
|
||||||
serde = "1.0.126"
|
serde = "1.0.126"
|
||||||
futures = "0.3.15"
|
futures = "0.3.15"
|
||||||
tokio = {version = "0.2.25", features = ["time", "process"]}
|
tokio = {version = "0.2.25", features = ["time", "process", "io-util"]}
|
||||||
|
|
73
src/main.rs
73
src/main.rs
|
@ -25,9 +25,10 @@ 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;
|
||||||
|
use actix_web::client::PayloadError;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "hello.html")]
|
#[template(path = "hello.html")]
|
||||||
|
@ -172,7 +173,9 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
|
||||||
let mut input = p.stdin.take().unwrap();
|
let mut input = p.stdin.take().unwrap();
|
||||||
payload.try_for_each(|bytes| {
|
payload.try_for_each(|bytes| {
|
||||||
// println!("{:?}", bytes);
|
// println!("{:?}", bytes);
|
||||||
input.write_all(bytes.bytes()).map_err(|e| actix_web::client::PayloadError::Io(e))
|
let write_all = input.write_all(bytes.bytes());
|
||||||
|
let res = write_all.map_err(|e| actix_web::client::PayloadError::Io(e));
|
||||||
|
return res;
|
||||||
// future::ready(Ok(()))
|
// future::ready(Ok(()))
|
||||||
}).await;
|
}).await;
|
||||||
println!("input sent");
|
println!("input sent");
|
||||||
|
@ -243,31 +246,51 @@ 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| {
|
||||||
let mut buff: [u8; 1024] = [0; 1024];
|
let mut buff: [u8; 1024] = [0; 1024];
|
||||||
match rdr.read(&mut buff[..]) {
|
let read = rdr.read(&mut buff[..]);
|
||||||
Ok(l) => {
|
let result = read.map_ok(|l| Some((Bytes::copy_from_slice(&buff[0..l]), 0)));
|
||||||
print!("{}", String::from_utf8_lossy(&buff[0..l]));
|
return result;
|
||||||
Ok(Bytes::copy_from_slice(&buff[0..l])) }
|
// match result {
|
||||||
Err(e) => {Err(e)}
|
// Ok(l) => {Ok(Some((Bytes::copy_from_slice(&buff[0..l]), 0)))}
|
||||||
}
|
// Err(e) => {Err(e)}
|
||||||
})
|
// }
|
||||||
.take_while(|bytes| {
|
|
||||||
match bytes {
|
// result.map(|l| {
|
||||||
Ok(bytes) => {future::ready(bytes.len() != 0)}
|
// print!("{}", String::from_utf8_lossy(&buff[0..l]));
|
||||||
Err(_) => {future::ready(false)}
|
// Some((Bytes::copy_from_slice(&buff[0..l]), 0))
|
||||||
}
|
// });
|
||||||
})
|
});
|
||||||
);
|
// 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