fix problem
This commit is contained in:
parent
b2c914734f
commit
9ac8b2f4fe
18
src/main.rs
18
src/main.rs
|
@ -150,7 +150,7 @@ async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web
|
|||
}
|
||||
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
|
||||
async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web::Path<(String, String)>, mut req: HttpRequest) -> io::Result<HttpResponse>{
|
||||
println!("enter git_proto");
|
||||
//println!("enter git_proto");
|
||||
let mut cmd = Command::new("git");
|
||||
cmd.arg("http-backend");
|
||||
|
||||
|
@ -174,12 +174,12 @@ async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web
|
|||
.stdin(Stdio::piped());
|
||||
let mut p: Child = cmd.spawn()?;
|
||||
let mut input = p.stdin.take().unwrap();
|
||||
println!("Displaying request...");
|
||||
//println!("Displaying request...");
|
||||
while let Some(Ok(bytes)) = payload.next().await {
|
||||
println!("request body : {}", String::from_utf8_lossy(bytes.bytes()));
|
||||
//println!("request body : {}", String::from_utf8_lossy(bytes.bytes()));
|
||||
input.write_all(bytes.bytes()).await;
|
||||
}
|
||||
println!("input sent");
|
||||
//println!("input sent");
|
||||
let mut rdr = tokio::io::BufReader::new(p.stdout.take().unwrap());
|
||||
|
||||
let mut headers = HashMap::new();
|
||||
|
@ -201,16 +201,16 @@ async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web
|
|||
.or_insert_with(Vec::new)
|
||||
.push(value.to_string());
|
||||
}
|
||||
println!("response headers : {:?}", headers);
|
||||
//println!("response headers : {:?}", headers);
|
||||
|
||||
let status_code : u16 = {
|
||||
let line = headers.remove("Status").unwrap_or_default();
|
||||
println!("{:?}", &line);
|
||||
// println!("{:?}", &line);
|
||||
let line = line.into_iter().next().unwrap_or_default();
|
||||
let parts : Vec<&str> = line.split(' ').collect();
|
||||
parts.into_iter().next().unwrap_or("").parse().unwrap_or(200)
|
||||
};
|
||||
println!("status code {}", status_code);
|
||||
// println!("status code {}", status_code);
|
||||
|
||||
let statusCode = match StatusCode::from_u16(status_code) {
|
||||
Ok(v) => {Ok(v)}
|
||||
|
@ -219,12 +219,12 @@ async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web
|
|||
let mut builder = HttpResponse::build(statusCode?);
|
||||
for (name, vec) in headers.iter() {
|
||||
for value in vec {
|
||||
println!("entry : ({}, {})", name, value.clone());
|
||||
// println!("entry : ({}, {})", name, value.clone());
|
||||
builder.header(name, value.clone());
|
||||
}
|
||||
}
|
||||
|
||||
println!("Write body...");
|
||||
// println!("Write body...");
|
||||
|
||||
let response = builder.streaming(ToStream(rdr));
|
||||
return Ok(response);
|
||||
|
|
|
@ -20,6 +20,14 @@ impl <T : tokio::io::AsyncRead> futures::Stream for ToStream<T>{
|
|||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||
let mut buff: [u8; 1024] = [0; 1024];
|
||||
let mut t = self.get_field();
|
||||
t.poll_read(cx, &mut buff[..]).map_ok(|l| {Bytes::copy_from_slice(&buff[0..l])}).map(|res| Some(res))
|
||||
let poll = t.poll_read(cx, &mut buff[..]);
|
||||
if let Poll::Ready(Ok(0)) = poll {
|
||||
// println!("end of response");
|
||||
return Poll::Ready(None);
|
||||
} else {
|
||||
let res = poll.map_ok(|l| {Bytes::copy_from_slice(&buff[0..l])}).map(|res| Some(res));
|
||||
// println!("poll_next : {:?}", res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue