Compare commits

..

No commits in common. "b76338f8024d79e376b01d0abb78198c53743732" and "b2c914734f78044e2421e77e7701c213e74bd6b7" have entirely different histories.

3 changed files with 22 additions and 40 deletions

View File

@ -1,3 +0,0 @@
pub struct Gitust {
pub repo_root_path : String,
}

View File

@ -2,7 +2,6 @@ mod git;
mod ite;
mod reader;
mod writer;
mod gitust;
use actix_files::Files;
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, Error, HttpRequest, HttpMessage};
@ -34,7 +33,6 @@ use actix_web::http::header::IntoHeaderValue;
use actix_web::client::PayloadError;
use crate::reader::ToStream;
use crate::writer::Writer;
use crate::gitust::Gitust;
#[derive(Template)]
#[template(path = "hello.html")]
@ -117,7 +115,7 @@ async fn chunk() -> HttpResponse {
return;
};
loop {
while true {
tokio::time::delay_for(std::time::Duration::from_secs(1)).await;
println!("send message");
tx.send(Ok(Bytes::from_static(b"coucou")));
@ -128,11 +126,7 @@ async fn chunk() -> HttpResponse {
}
#[get("/git/{owner}/{repo}.git")]
async fn git_main(
web::Path((owner, reponame)): web::Path<(String, String)>,
web::Query(GitWebQ{commit : commitnameopt, path : pathopt}) : web::Query<GitWebQ>,
gitust : web::Data<Gitust>
) -> impl Responder {
async fn git_main(web::Path((owner, reponame)): web::Path<(String, String)>, web::Query(GitWebQ{commit : commitnameopt, path : pathopt}) : web::Query<GitWebQ>) -> impl Responder {
let commitname = match commitnameopt {
None => {"master".to_string()}
Some(s) => {s}
@ -155,20 +149,22 @@ async fn git_main(
GitMainTemplate { repo, browse : browse, root : path, user_opt : Some(user)}
}
//#[get("/git/{owner}/{repo}.git/{path:.*}")]
async fn git_proto(
mut payload : web::Payload,
web::Path((owner, reponame)): web::Path<(String, String)>,
mut req: HttpRequest,
gitust : web::Data<Gitust>
) -> io::Result<HttpResponse>{
//println!("enter git_proto");
async fn git_proto(mut 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");
cmd.arg("http-backend");
// Required environment variables
cmd.env("REQUEST_METHOD", req.method().as_str());
cmd.env("GIT_PROJECT_ROOT", &gitust.repo_root_path);
cmd.env("PATH_INFO", format!("/{}/{}.git",owner, reponame));
cmd.env("GIT_PROJECT_ROOT", "/home/hubert");
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());
@ -178,12 +174,12 @@ async fn git_proto(
.stdin(Stdio::piped());
let mut p: Child = cmd.spawn()?;
let mut input = p.stdin.take().unwrap();
//println!("Displaying request...");
println!("Displaying request...");
while let Some(Ok(bytes)) = payload.next().await {
//println!("request body : {}", String::from_utf8_lossy(bytes.bytes()));
println!("request body : {}", String::from_utf8_lossy(bytes.bytes()));
input.write_all(bytes.bytes()).await;
}
//println!("input sent");
println!("input sent");
let mut rdr = tokio::io::BufReader::new(p.stdout.take().unwrap());
let mut headers = HashMap::new();
@ -205,16 +201,16 @@ async fn git_proto(
.or_insert_with(Vec::new)
.push(value.to_string());
}
//println!("response headers : {:?}", headers);
println!("response headers : {:?}", headers);
let status_code : u16 = {
let line = headers.remove("Status").unwrap_or_default();
// println!("{:?}", &line);
println!("{:?}", &line);
let line = line.into_iter().next().unwrap_or_default();
let parts : Vec<&str> = line.split(' ').collect();
parts.into_iter().next().unwrap_or("").parse().unwrap_or(200)
};
// println!("status code {}", status_code);
println!("status code {}", status_code);
let statusCode = match StatusCode::from_u16(status_code) {
Ok(v) => {Ok(v)}
@ -223,12 +219,12 @@ async fn git_proto(
let mut builder = HttpResponse::build(statusCode?);
for (name, vec) in headers.iter() {
for value in vec {
// println!("entry : ({}, {})", name, value.clone());
println!("entry : ({}, {})", name, value.clone());
builder.header(name, value.clone());
}
}
// println!("Write body...");
println!("Write body...");
let response = builder.streaming(ToStream(rdr));
return Ok(response);
@ -287,9 +283,6 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
let auth = HttpAuthentication::basic(basic_auth_validator);
App::new()
.data(Gitust {
repo_root_path: "/home/hubert/gitust".to_string(),
})
.wrap(Logger::default())
// .wrap(Logger::new("%a %{User-Agent}i"))
.wrap(CookieSession::signed(&[0; 32]).secure(false))

View File

@ -20,14 +20,6 @@ impl <T : tokio::io::AsyncRead> futures::Stream for ToStream<T>{
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
let mut buff: [u8; 1024] = [0; 1024];
let mut t = self.get_field();
let poll = t.poll_read(cx, &mut buff[..]);
if let Poll::Ready(Ok(0)) = poll {
// println!("end of response");
return Poll::Ready(None);
} else {
let res = poll.map_ok(|l| {Bytes::copy_from_slice(&buff[0..l])}).map(|res| Some(res));
// println!("poll_next : {:?}", res);
return res;
}
t.poll_read(cx, &mut buff[..]).map_ok(|l| {Bytes::copy_from_slice(&buff[0..l])}).map(|res| Some(res))
}
}