diff --git a/.gitignore b/.gitignore index f2f9e58..869df07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -target +/target Cargo.lock \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 94c2741..f212adb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,9 @@ use crate::ite::SuperIterator; use std::ops::Add; use std::path::{PathBuf, Path}; use serde::Deserialize; +use std::process::{Command, Stdio}; +use actix_web::http::header; +use std::io; #[derive(Template)] #[template(path = "hello.html")] @@ -117,6 +120,29 @@ async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web } //#[get("/git/{owner}/{repo}.git/{path:.*}")] async fn git_proto(web::Path((owner, reponame)): web::Path<(String, String)>, req: HttpRequest) -> impl Responder{ + let mut cmd = Command::new("git"); + cmd.arg("http-backend"); + + // Required environment variables + cmd.env("REQUEST_METHOD", req.method().as_str()); + cmd.env("GIT_PROJECT_ROOT", "/home/hubert/test.git"); + cmd.env( + "PATH_INFO", + if req.path().starts_with('/') { + req.path().to_string() + } else { + format!("/{}", req.path()) + }, + ); + cmd.env("REMOTE_USER", ""); + //cmd.env("REMOTE_ADDR", req.remote_addr().to_string()); + cmd.env("QUERY_STRING", req.query_string().unwrap_or_default()); + //cmd.env("CONTENT_TYPE", header(req, header::CONTENT_TYPE)); + cmd.stderr(Stdio::inherit()) + .stdout(Stdio::piped()) + .stdin(Stdio::piped()); + let mut p = cmd.spawn()?; + io::copy(&mut req.body(), &mut p.stdin.take().unwrap())?; "not yet implemented" }