Compare commits

...

5 Commits

Author SHA1 Message Date
Hubert ee1efbe8aa push OK, clone KO 2021-07-08 08:32:23 +02:00
Hubert e6ff105b17 push OK, clone KO 2021-07-08 08:20:59 +02:00
Hubert 4f933e2526 push OK, clone KO 2021-07-08 08:02:44 +02:00
Hubert 7f4978140e git http fonctionne 2021-07-08 07:03:27 +02:00
Hubert be7bd3a20d save 2021-07-08 06:44:38 +02:00
1 changed files with 21 additions and 10 deletions

View File

@ -18,11 +18,11 @@ use crate::ite::SuperIterator;
use std::ops::Add;
use std::path::{PathBuf, Path};
use serde::Deserialize;
use std::process::{Command, Stdio};
use std::process::{Command, Stdio, Child};
use actix_web::http::{header, StatusCode};
use std::io;
use std::collections::HashMap;
use std::io::{Read, BufRead, Write};
use std::io::{Read, BufRead, Write, ErrorKind};
use futures::{StreamExt, TryStreamExt, future};
use actix_web::web::Buf;
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)}
}
//#[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");
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("GIT_PROJECT_ROOT", "/home/hubert");
cmd.env(
"PATH_INFO",
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())
.stdout(Stdio::piped())
.stdin(Stdio::piped());
let mut p = cmd.spawn()?;
let mut p: Child = cmd.spawn()?;
//p.stdin.take().unwrap().write()
let mut input = p.stdin.take().unwrap();
payload.try_for_each(|bytes| {
p.stdin.take().unwrap().write(bytes.bytes());
// println!("{:?}", bytes);
input.write(bytes.bytes());
future::ready(Ok(()))
});
}).await;
println!("input sent");
//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.
@ -179,12 +183,18 @@ async fn git_proto(payload : web::Payload, web::Path((owner, reponame)): web::Pa
let status_code : u16 = {
let line = headers.remove("Status").unwrap_or_default();
// println!("{:?}", &line);
let line = line.into_iter().next().unwrap_or_default();
let mut parts = line.splitn(1, ' ');
parts.next().unwrap_or("").parse().unwrap_or(200)
let parts : Vec<&str> = line.split(' ').collect();
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 value in vec {
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();
rdr.read_to_end(&mut body)?;
// println!("{}", String::from_utf8(body.clone()).expect("bad utf8"));
return Ok(builder.body(body));
}