Compare commits

..

No commits in common. "e267539e53ca87e8f830032b169bb71819031ced" and "4eb34b80605424288bcffa4ba6ae9aa20c059ce1" have entirely different histories.

2 changed files with 7 additions and 66 deletions

View File

@ -15,4 +15,3 @@ askama = "0.10.5"
askama_actix = "0.11.1"
env_logger = "0.8.4"
serde = "1.0.126"
futures = "0.3.15"

View File

@ -2,7 +2,7 @@ mod git;
mod ite;
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};
use askama_actix::Template;
use actix_session::{Session, CookieSession};
use actix_web_httpauth::headers::authorization::{Authorization, Basic};
@ -19,13 +19,8 @@ use std::ops::Add;
use std::path::{PathBuf, Path};
use serde::Deserialize;
use std::process::{Command, Stdio};
use actix_web::http::{header, StatusCode};
use actix_web::http::header;
use std::io;
use std::collections::HashMap;
use std::io::{Read, BufRead, Write};
use futures::{StreamExt, TryStreamExt, future};
use actix_web::web::Buf;
use actix_web::http::header::IntoHeaderValue;
#[derive(Template)]
#[template(path = "hello.html")]
@ -124,7 +119,7 @@ async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web
GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)}
}
//#[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(web::Path((owner, reponame)): web::Path<(String, String)>, req: HttpRequest) -> impl Responder{
let mut cmd = Command::new("git");
cmd.arg("http-backend");
@ -141,67 +136,14 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
);
cmd.env("REMOTE_USER", "");
//cmd.env("REMOTE_ADDR", req.remote_addr().to_string());
cmd.env("QUERY_STRING", req.query_string());
cmd.env("CONTENT_TYPE", header(&req, header::CONTENT_TYPE));
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()?;
//p.stdin.take().unwrap().write()
payload.try_for_each(|bytes| {
p.stdin.take().unwrap().write(bytes.bytes());
future::ready(Ok(()))
});
//io::copy(&mut req.take_payload(), &mut p.stdin.take().unwrap())?;
// Parse the headers coming out, and the pass through the rest of the
// process back down the stack.
//
// Note that we have to be careful to not drop the process which will wait
// for the process to exit (and we haven't read stdout)
let mut rdr = io::BufReader::new(p.stdout.take().unwrap());
let mut headers = HashMap::new();
for line in rdr.by_ref().lines() {
let line = line?;
if line == "" || line == "\r" {
break;
}
let mut parts = line.splitn(2, ':');
let key = parts.next().unwrap();
let value = parts.next().unwrap();
let value = &value[1..];
headers
.entry(key.to_string())
.or_insert_with(Vec::new)
.push(value.to_string());
}
let status_code : u16 = {
let line = headers.remove("Status").unwrap_or_default();
let line = line.into_iter().next().unwrap_or_default();
let mut parts = line.splitn(1, ' ');
parts.next().unwrap_or("").parse().unwrap_or(200)
};
let mut builder = HttpResponse::build(StatusCode::from_u16(status_code)?);
for (name, vec) in headers.iter() {
for value in vec {
builder.header(name, value.clone());
}
}
let mut body = Vec::new();
rdr.read_to_end(&mut body)?;
return Ok(builder.body(body));
}
fn header(req: &HttpRequest, name: header::HeaderName) -> &str {
req.headers()
.get(name)
.map(|value| value.to_str().unwrap_or_default())
.unwrap_or_default()
io::copy(&mut req.body(), &mut p.stdin.take().unwrap())?;
"not yet implemented"
}
#[post("/echo")]