From 7d8bfbbb62ac034472381e4d4be32ee9ee336206 Mon Sep 17 00:00:00 2001 From: Hubert Date: Thu, 8 Jul 2021 14:26:34 +0200 Subject: [PATCH 1/3] save --- src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 16b2a33..d928de1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,8 +23,8 @@ 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; #[derive(Template)] @@ -201,7 +201,16 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa } } + println!("Write body..."); let mut body = Vec::new(); + //rdr.bytes() + let mut buff : [u8; 1024] = [0; 1024]; + builder.streaming(stream::repeat_with(|| { + match rdr.read(&buff) { + Ok(l) => {Bytes::copy_from_slice(&buff[0..l])} + Err(_) => {} + } + })); rdr.read_to_end(&mut body)?; // println!("{}", String::from_utf8(body.clone()).expect("bad utf8")); return Ok(builder.body(body)); From e4351f721797aa22f1e72da7896828f1e0f6b045 Mon Sep 17 00:00:00 2001 From: Hubert Date: Thu, 8 Jul 2021 20:51:46 +0200 Subject: [PATCH 2/3] save --- src/main.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d928de1..ef4cb37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -202,18 +202,20 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa } println!("Write body..."); - let mut body = Vec::new(); + //let mut body = Vec::new(); //rdr.bytes() let mut buff : [u8; 1024] = [0; 1024]; - builder.streaming(stream::repeat_with(|| { - match rdr.read(&buff) { - Ok(l) => {Bytes::copy_from_slice(&buff[0..l])} - Err(_) => {} + let response = builder.streaming(stream::repeat_with(|| { + 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)?; + //rdr.read_to_end(&mut body)?; // println!("{}", String::from_utf8(body.clone()).expect("bad utf8")); - return Ok(builder.body(body)); + return Ok(response); } From 08113e45fb2472050ee2643bcb166112377fa230 Mon Sep 17 00:00:00 2001 From: Hubert Date: Thu, 8 Jul 2021 20:53:24 +0200 Subject: [PATCH 3/3] save --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ef4cb37..f2baaf4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -204,8 +204,8 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa println!("Write body..."); //let mut body = Vec::new(); //rdr.bytes() - let mut buff : [u8; 1024] = [0; 1024]; 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)}