Compare commits
No commits in common. "ee1efbe8aa22d25306bff203d90443e1f6f634b7" and "e267539e53ca87e8f830032b169bb71819031ced" have entirely different histories.
ee1efbe8aa
...
e267539e53
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, Child};
|
use std::process::{Command, Stdio};
|
||||||
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, ErrorKind};
|
use std::io::{Read, BufRead, Write};
|
||||||
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,14 +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) -> io::Result<HttpResponse>{
|
async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Path<(String, String)>, mut req: HttpRequest) -> impl Responder{
|
||||||
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");
|
cmd.env("GIT_PROJECT_ROOT", "/home/hubert/test.git");
|
||||||
cmd.env(
|
cmd.env(
|
||||||
"PATH_INFO",
|
"PATH_INFO",
|
||||||
if req.path().starts_with('/') {
|
if req.path().starts_with('/') {
|
||||||
|
@ -147,15 +146,12 @@ 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: Child = cmd.spawn()?;
|
let mut p = 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| {
|
||||||
// println!("{:?}", bytes);
|
p.stdin.take().unwrap().write(bytes.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.
|
||||||
|
@ -183,18 +179,12 @@ 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 parts : Vec<&str> = line.split(' ').collect();
|
let mut parts = line.splitn(1, ' ');
|
||||||
parts.into_iter().next().unwrap_or("").parse().unwrap_or(200)
|
parts.next().unwrap_or("").parse().unwrap_or(200)
|
||||||
};
|
};
|
||||||
// println!("{}", status_code);
|
|
||||||
|
|
||||||
let statusCode = match StatusCode::from_u16(status_code) {
|
let mut builder = HttpResponse::build(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());
|
||||||
|
@ -203,7 +193,6 @@ 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