This commit is contained in:
Hubert 2021-07-08 06:44:38 +02:00
parent e267539e53
commit be7bd3a20d
1 changed files with 14 additions and 8 deletions

View File

@ -18,11 +18,11 @@ 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 std::process::{Command, Stdio}; use std::process::{Command, Stdio, Child};
use actix_web::http::{header, StatusCode}; use actix_web::http::{header, StatusCode};
use std::io; use std::io;
use std::collections::HashMap; use std::collections::HashMap;
use std::io::{Read, BufRead, Write}; use std::io::{Read, BufRead, Write, ErrorKind};
use futures::{StreamExt, TryStreamExt, future}; use futures::{StreamExt, TryStreamExt, future};
use actix_web::web::Buf; use actix_web::web::Buf;
use actix_web::http::header::IntoHeaderValue; use actix_web::http::header::IntoHeaderValue;
@ -124,13 +124,13 @@ async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web
GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)} GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)}
} }
//#[get("/git/{owner}/{repo}.git/{path:.*}")] //#[get("/git/{owner}/{repo}.git/{path:.*}")]
async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Path<(String, String)>, mut req: HttpRequest) -> impl Responder{ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Path<(String, String)>, mut req: HttpRequest) -> io::Result<HttpResponse>{
let mut cmd = Command::new("git"); let mut cmd = Command::new("git");
cmd.arg("http-backend"); cmd.arg("http-backend");
// Required environment variables // Required environment variables
cmd.env("REQUEST_METHOD", req.method().as_str()); cmd.env("REQUEST_METHOD", req.method().as_str());
cmd.env("GIT_PROJECT_ROOT", "/home/hubert/test.git"); cmd.env("GIT_PROJECT_ROOT", "/home/hubert");
cmd.env( cmd.env(
"PATH_INFO", "PATH_INFO",
if req.path().starts_with('/') { if req.path().starts_with('/') {
@ -146,7 +146,7 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
cmd.stderr(Stdio::inherit()) cmd.stderr(Stdio::inherit())
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stdin(Stdio::piped()); .stdin(Stdio::piped());
let mut p = cmd.spawn()?; let mut p: Child = cmd.spawn()?;
//p.stdin.take().unwrap().write() //p.stdin.take().unwrap().write()
payload.try_for_each(|bytes| { payload.try_for_each(|bytes| {
p.stdin.take().unwrap().write(bytes.bytes()); p.stdin.take().unwrap().write(bytes.bytes());
@ -179,12 +179,18 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
let status_code : u16 = { let status_code : u16 = {
let line = headers.remove("Status").unwrap_or_default(); let line = headers.remove("Status").unwrap_or_default();
// println!("{:?}", &line);
let line = line.into_iter().next().unwrap_or_default(); let line = line.into_iter().next().unwrap_or_default();
let mut parts = line.splitn(1, ' '); let parts : Vec<&str> = line.split(' ').collect();
parts.next().unwrap_or("").parse().unwrap_or(200) parts.into_iter().next().unwrap_or("").parse().unwrap_or(200)
}; };
// println!("{}", status_code);
let mut builder = HttpResponse::build(StatusCode::from_u16(status_code)?); let statusCode = match StatusCode::from_u16(status_code) {
Ok(v) => {Ok(v)}
Err(ioe) => {Err(io::Error::new(ErrorKind::Other, "Invalid HTTP status code"))}
};
let mut builder = HttpResponse::build(statusCode?);
for (name, vec) in headers.iter() { for (name, vec) in headers.iter() {
for value in vec { for value in vec {
builder.header(name, value.clone()); builder.header(name, value.clone());