diff --git a/src/main.rs b/src/main.rs index d373abf..74c7d8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,10 +23,9 @@ use actix_web::http::{header, StatusCode}; use std::io; use std::collections::HashMap; use std::io::{Read, BufRead, Write, ErrorKind}; -use futures::{StreamExt, TryStreamExt, future}; -use actix_web::web::Buf; +use futures::{StreamExt, TryStreamExt, future, stream}; +use actix_web::web::{Buf, Bytes}; use actix_web::http::header::IntoHeaderValue; -use futures::stream; #[derive(Template)] #[template(path = "hello.html")] @@ -204,13 +203,21 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa } } - println!("headers written"); - - let mut body = Vec::new(); - rdr.read_to_end(&mut body)?; - println!("{}", String::from_utf8(body.clone()).expect("bad utf8")); - // builder.streaming(stream::repeat_with(rdr.rea)) - return Ok(builder.body(body)); + println!("Write body..."); + //let mut body = Vec::new(); + //rdr.bytes() + let response = builder.streaming(stream::repeat_with(|| { + let mut buff : [u8; 1024] = [0; 1024]; + match rdr.read(&mut buff[..]) { + Ok(l) => {Ok(Bytes::copy_from_slice(&buff[0..l]))} + Err(e) => {Err(e)} + } + }).take_while(|bytes| { + future::ready(bytes.is_ok()) + })); + //rdr.read_to_end(&mut body)?; + // println!("{}", String::from_utf8(body.clone()).expect("bad utf8")); + return Ok(response); }