fix bug with header parsing (\r\n) but still buggy

This commit is contained in:
Hubert 2021-07-13 21:53:20 +02:00
parent a4f4cb3033
commit b2c914734f
1 changed files with 6 additions and 10 deletions

View File

@ -174,7 +174,9 @@ async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web
.stdin(Stdio::piped()); .stdin(Stdio::piped());
let mut p: Child = cmd.spawn()?; let mut p: Child = cmd.spawn()?;
let mut input = p.stdin.take().unwrap(); let mut input = p.stdin.take().unwrap();
println!("Displaying request...");
while let Some(Ok(bytes)) = payload.next().await { while let Some(Ok(bytes)) = payload.next().await {
println!("request body : {}", String::from_utf8_lossy(bytes.bytes()));
input.write_all(bytes.bytes()).await; input.write_all(bytes.bytes()).await;
} }
println!("input sent"); println!("input sent");
@ -192,13 +194,14 @@ async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web
let mut parts = line.splitn(2, ':'); let mut parts = line.splitn(2, ':');
let key = parts.next().unwrap(); let key = parts.next().unwrap();
let value = parts.next().unwrap(); let value = parts.next().unwrap();
let value = &value[1..]; let value_len = value.len();
let value = &value[1..value_len-2];
headers headers
.entry(key.to_string()) .entry(key.to_string())
.or_insert_with(Vec::new) .or_insert_with(Vec::new)
.push(value.to_string()); .push(value.to_string());
} }
println!("headers : {:?}", headers); println!("response headers : {:?}", headers);
let status_code : u16 = { let status_code : u16 = {
let line = headers.remove("Status").unwrap_or_default(); let line = headers.remove("Status").unwrap_or_default();
@ -216,20 +219,13 @@ async fn git_proto(mut payload : web::Payload, web::Path((owner, reponame)): web
let mut builder = HttpResponse::build(statusCode?); let mut builder = HttpResponse::build(statusCode?);
for (name, vec) in headers.iter() { for (name, vec) in headers.iter() {
for value in vec { for value in vec {
println!("entry : ({}, {})", name, value.clone());
builder.header(name, value.clone()); builder.header(name, value.clone());
} }
} }
println!("Write body..."); println!("Write body...");
// let unfold = stream::try_unfold(rdr, move |mut rdr| {
// let mut buff: [u8; 1024] = [0; 1024];
// let read = rdr.read(&mut buff[..]);
// let result = read.map_ok(|l| Some((Bytes::copy_from_slice(&buff[0..l]), rdr)));
// return result;
// });
// pin_mut!(unfold);
// let response = builder.streaming(unfold);
let response = builder.streaming(ToStream(rdr)); let response = builder.streaming(ToStream(rdr));
return Ok(response); return Ok(response);
} }