Compare commits
5 Commits
e267539e53
...
ee1efbe8aa
Author | SHA1 | Date |
---|---|---|
Hubert | ee1efbe8aa | |
Hubert | e6ff105b17 | |
Hubert | 4f933e2526 | |
Hubert | 7f4978140e | |
Hubert | be7bd3a20d |
31
src/main.rs
31
src/main.rs
|
@ -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,14 @@ 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>{
|
||||||
|
println!("enter git_proto");
|
||||||
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,12 +147,15 @@ 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()
|
||||||
|
let mut input = p.stdin.take().unwrap();
|
||||||
payload.try_for_each(|bytes| {
|
payload.try_for_each(|bytes| {
|
||||||
p.stdin.take().unwrap().write(bytes.bytes());
|
// println!("{:?}", bytes);
|
||||||
|
input.write(bytes.bytes());
|
||||||
future::ready(Ok(()))
|
future::ready(Ok(()))
|
||||||
});
|
}).await;
|
||||||
|
println!("input sent");
|
||||||
//io::copy(&mut req.take_payload(), &mut p.stdin.take().unwrap())?;
|
//io::copy(&mut req.take_payload(), &mut p.stdin.take().unwrap())?;
|
||||||
// Parse the headers coming out, and the pass through the rest of the
|
// Parse the headers coming out, and the pass through the rest of the
|
||||||
// process back down the stack.
|
// process back down the stack.
|
||||||
|
@ -179,12 +183,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());
|
||||||
|
@ -193,6 +203,7 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
|
||||||
|
|
||||||
let mut body = Vec::new();
|
let mut body = Vec::new();
|
||||||
rdr.read_to_end(&mut body)?;
|
rdr.read_to_end(&mut body)?;
|
||||||
|
// println!("{}", String::from_utf8(body.clone()).expect("bad utf8"));
|
||||||
return Ok(builder.body(body));
|
return Ok(builder.body(body));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue