save
This commit is contained in:
parent
4823c55e8b
commit
439e9546e7
25
src/main.rs
25
src/main.rs
|
@ -1,6 +1,7 @@
|
||||||
mod git;
|
mod git;
|
||||||
mod ite;
|
mod ite;
|
||||||
mod tostream;
|
mod reader;
|
||||||
|
mod writer;
|
||||||
|
|
||||||
use actix_files::Files;
|
use actix_files::Files;
|
||||||
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, Error, HttpRequest, HttpMessage};
|
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, Error, HttpRequest, HttpMessage};
|
||||||
|
@ -19,8 +20,8 @@ use crate::ite::SuperIterator;
|
||||||
use std::ops::Add;
|
use std::ops::Add;
|
||||||
use std::path::{PathBuf, Path};
|
use std::path::{PathBuf, Path};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tokio::process::{Command, Child};
|
use tokio::process::{Command, Child, ChildStdout};
|
||||||
use tokio::io::{AsyncWriteExt, AsyncBufReadExt, AsyncReadExt};
|
use tokio::io::{AsyncWriteExt, AsyncBufReadExt, AsyncReadExt, BufReader};
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
use actix_web::http::{header, StatusCode};
|
use actix_web::http::{header, StatusCode};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -30,6 +31,7 @@ use futures::{Stream, StreamExt, TryStreamExt, future, stream, TryFutureExt, pin
|
||||||
use actix_web::web::{Buf, Bytes};
|
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;
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "hello.html")]
|
#[template(path = "hello.html")]
|
||||||
|
@ -183,7 +185,7 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
|
||||||
let mut rdr = tokio::io::BufReader::new(p.stdout.take().unwrap());
|
let mut rdr = tokio::io::BufReader::new(p.stdout.take().unwrap());
|
||||||
|
|
||||||
let mut headers = HashMap::new();
|
let mut headers = HashMap::new();
|
||||||
while true {
|
loop {
|
||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
let len = rdr.read_line(&mut line).await?;
|
let len = rdr.read_line(&mut line).await?;
|
||||||
if line == "" || line == "\r" {
|
if line == "" || line == "\r" {
|
||||||
|
@ -223,14 +225,15 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
|
||||||
|
|
||||||
println!("Write body...");
|
println!("Write body...");
|
||||||
|
|
||||||
let unfold = stream::try_unfold(rdr, move |mut rdr| {
|
// let unfold = stream::try_unfold(rdr, move |mut rdr| {
|
||||||
let mut buff: [u8; 1024] = [0; 1024];
|
// let mut buff: [u8; 1024] = [0; 1024];
|
||||||
let read = rdr.read(&mut buff[..]);
|
// let read = rdr.read(&mut buff[..]);
|
||||||
let result = read.map_ok(|l| Some((Bytes::copy_from_slice(&buff[0..l]), rdr)));
|
// let result = read.map_ok(|l| Some((Bytes::copy_from_slice(&buff[0..l]), rdr)));
|
||||||
return result;
|
// return result;
|
||||||
});
|
// });
|
||||||
// pin_mut!(unfold);
|
// pin_mut!(unfold);
|
||||||
let response = builder.streaming(unfold);
|
// let response = builder.streaming(unfold);
|
||||||
|
let response = builder.streaming(ToStream(rdr));
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use futures::{Stream, AsyncRead};
|
// use futures::{Stream, AsyncRead, TryStream};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use actix_web::web::Bytes;
|
use actix_web::web::Bytes;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
|
||||||
struct ToStream<T>(T);
|
pub struct ToStream<T>(pub T);
|
||||||
|
|
||||||
impl<T> ToStream<T> {
|
impl<T> ToStream<T> {
|
||||||
fn get_field(self: Pin<&mut Self>) -> Pin<&mut T> {
|
fn get_field(self: Pin<&mut Self>) -> Pin<&mut T> {
|
||||||
|
@ -14,7 +14,7 @@ impl<T> ToStream<T> {
|
||||||
|
|
||||||
impl <T : Unpin> Unpin for ToStream<T>{}
|
impl <T : Unpin> Unpin for ToStream<T>{}
|
||||||
|
|
||||||
impl <T : AsyncRead> Stream for ToStream<T>{
|
impl <T : tokio::io::AsyncRead> futures::Stream for ToStream<T>{
|
||||||
type Item = Result<Bytes, Error>;
|
type Item = Result<Bytes, Error>;
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
|
@ -0,0 +1,8 @@
|
||||||
|
use actix_web::web::Bytes;
|
||||||
|
|
||||||
|
pub struct Writer<T>{
|
||||||
|
pub t : T,
|
||||||
|
pub bytes : Bytes,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl
|
Loading…
Reference in New Issue