From b22b5f81c79309b8115c049421c0f8eba1ac6a7a Mon Sep 17 00:00:00 2001 From: Hubert Date: Sun, 11 Jul 2021 09:53:38 +0200 Subject: [PATCH] save --- Cargo.toml | 2 +- src/main.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4e9d1ba..8b31c48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ askama_actix = "0.11.1" env_logger = "0.8.4" serde = "1.0.126" futures = "0.3.15" -tokio = {version = "0.2.25", features = ["time", "process"]} +tokio = {version = "0.2.25", features = ["time", "process", "io-util"]} diff --git a/src/main.rs b/src/main.rs index 12bf672..7248883 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ use std::io::{Read, BufRead, Write, ErrorKind}; use futures::{Stream, StreamExt, TryStreamExt, future, stream, TryFutureExt, pin_mut}; use actix_web::web::{Buf, Bytes}; use actix_web::http::header::IntoHeaderValue; +use actix_web::client::PayloadError; #[derive(Template)] #[template(path = "hello.html")] @@ -172,7 +173,9 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa let mut input = p.stdin.take().unwrap(); payload.try_for_each(|bytes| { // println!("{:?}", bytes); - input.write_all(bytes.bytes()).map_err(|e| actix_web::client::PayloadError::Io(e)) + 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"); @@ -254,19 +257,22 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa // } // }); - let unfold = stream::try_unfold(0, |_useless| async move { + let unfold = stream::try_unfold(0, |_useless| { let mut buff: [u8; 1024] = [0; 1024]; - let result = rdr.read(&mut buff[..]).await; - match result { - Ok(l) => {Ok(Some((Bytes::copy_from_slice(&buff[0..l]), 0)))} - Err(e) => {Err(e)} - } + let read = rdr.read(&mut buff[..]); + let result = read.map_ok(|l| Some((Bytes::copy_from_slice(&buff[0..l]), 0))); + return result; + // match result { + // Ok(l) => {Ok(Some((Bytes::copy_from_slice(&buff[0..l]), 0)))} + // Err(e) => {Err(e)} + // } + // result.map(|l| { // print!("{}", String::from_utf8_lossy(&buff[0..l])); // Some((Bytes::copy_from_slice(&buff[0..l]), 0)) // }); }); - pin_mut!(unfold); + // pin_mut!(unfold); let response = builder.streaming(unfold); // let response = builder.streaming(stream::repeat_with(move || {