This commit is contained in:
Hubert 2021-07-13 14:44:14 +02:00
parent 439e9546e7
commit f007c47dbb
2 changed files with 14 additions and 13 deletions

View File

@ -32,6 +32,7 @@ use actix_web::web::{Buf, Bytes};
use actix_web::http::header::IntoHeaderValue; use actix_web::http::header::IntoHeaderValue;
use actix_web::client::PayloadError; use actix_web::client::PayloadError;
use crate::reader::ToStream; use crate::reader::ToStream;
use crate::writer::Writer;
#[derive(Template)] #[derive(Template)]
#[template(path = "hello.html")] #[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()?; let mut p: Child = cmd.spawn()?;
//p.stdin.take().unwrap().write() //p.stdin.take().unwrap().write()
let mut input = p.stdin.take().unwrap(); let mut input = p.stdin.take().unwrap();
payload.try_for_each(|bytes| { let mut writer = Writer(input);
// println!("{:?}", bytes); payload.try_for_each(|bytes| writer.write(bytes)).await; // le faire au niveau de payload et pas de input
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;
println!("input sent"); println!("input sent");
let mut rdr = tokio::io::BufReader::new(p.stdout.take().unwrap()); let mut rdr = tokio::io::BufReader::new(p.stdout.take().unwrap());

View File

@ -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<T>{ pub struct Writer<T>(pub T);
pub t : T,
pub bytes : Bytes, impl <T : tokio::io::AsyncWrite + Unpin> Writer<T> {
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;
}
} }
impl