diff --git a/src/main.rs b/src/main.rs index 7560eae..a6b5aea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ use actix_web::web::{Buf, Bytes}; use actix_web::http::header::IntoHeaderValue; use actix_web::client::PayloadError; use crate::reader::ToStream; +use crate::writer::Writer; #[derive(Template)] #[template(path = "hello.html")] @@ -174,13 +175,8 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa let mut p: Child = cmd.spawn()?; //p.stdin.take().unwrap().write() let mut input = p.stdin.take().unwrap(); - payload.try_for_each(|bytes| { - // println!("{:?}", bytes); - let write_all = input.write_all(bytes.bytes()); - let res = write_all.map_err(|e| actix_web::client::PayloadError::Io(e)); - return res; - // future::ready(Ok(())) - }).await; + let mut writer = Writer(input); + payload.try_for_each(|bytes| writer.write(bytes)).await; // le faire au niveau de payload et pas de input println!("input sent"); let mut rdr = tokio::io::BufReader::new(p.stdout.take().unwrap()); diff --git a/src/writer.rs b/src/writer.rs index 9dfea19..c4f4119 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -1,8 +1,13 @@ -use actix_web::web::Bytes; +use actix_web::web::{Bytes, Buf}; +use tokio::io::AsyncWriteExt; +use actix_web::error::PayloadError; -pub struct Writer{ - pub t : T, - pub bytes : Bytes, -} +pub struct Writer(pub T); -impl \ No newline at end of file +impl Writer { + pub async fn write(&mut self, bytes : Bytes) -> Result<(), PayloadError> { + let write_all = self.0.write_all(bytes.bytes()).await; + let res = write_all.map_err(|e| actix_web::client::PayloadError::Io(e)); + return res; + } +} \ No newline at end of file