From b2c914734f78044e2421e77e7701c213e74bd6b7 Mon Sep 17 00:00:00 2001 From: Hubert Date: Tue, 13 Jul 2021 21:53:20 +0200 Subject: [PATCH] fix bug with header parsing (\r\n) but still buggy --- src/main.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index c3f7f25..f1dc9de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -174,7 +174,9 @@ 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..."); while let Some(Ok(bytes)) = payload.next().await { + println!("request body : {}", String::from_utf8_lossy(bytes.bytes())); input.write_all(bytes.bytes()).await; } 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 key = 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 .entry(key.to_string()) .or_insert_with(Vec::new) .push(value.to_string()); } - println!("headers : {:?}", headers); + println!("response headers : {:?}", headers); let status_code : u16 = { 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?); for (name, vec) in headers.iter() { for value in vec { + println!("entry : ({}, {})", name, value.clone()); builder.header(name, value.clone()); } } 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)); return Ok(response); }