about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--corgi/src/main.rs49
1 files changed, 12 insertions, 37 deletions
diff --git a/corgi/src/main.rs b/corgi/src/main.rs
index 9831331..aa7bf4a 100644
--- a/corgi/src/main.rs
+++ b/corgi/src/main.rs
@@ -10,18 +10,13 @@ use http_body_util::{BodyExt, Full};
 use hyper::{
 	HeaderMap, Request, Response, StatusCode,
 	body::{Bytes, Incoming},
-	header::{self, HeaderValue},
+	header::HeaderValue,
 	server::conn::http1,
 	service::Service,
 };
 use hyper_util::rt::TokioIo;
 use regex_lite::Regex;
-use tokio::{
-	io::{AsyncWriteExt, BufWriter},
-	net::TcpListener,
-	process::Command,
-	runtime::Runtime,
-};
+use tokio::{io::AsyncWriteExt, net::TcpListener, process::Command, runtime::Runtime};
 
 #[derive(Clone, Debug)]
 pub struct Settings {
@@ -166,9 +161,6 @@ impl Svc {
 			.unwrap_or_default()
 			.to_owned();
 
-		println!("!!! new request. type {content_type} // {method}");
-		println!("!!! {path}?{query}");
-
 		let uagent = headers
 			.get("user-agent")
 			.map(|s| s.to_str().ok())
@@ -225,8 +217,7 @@ impl Svc {
 		};
 
 		let start_cgi = Instant::now();
-		let cgi_response =
-			Self::call_and_parse_cgi(cmd, cgibody, caddr.ip(), debugcgi, &path).await;
+		let cgi_response = Self::call_and_parse_cgi(cmd, cgibody).await;
 		let cgi_time = start_cgi.elapsed();
 
 		let status = StatusCode::from_u16(cgi_response.status).unwrap();
@@ -282,13 +273,7 @@ impl Svc {
 		}
 	}
 
-	async fn call_and_parse_cgi(
-		mut cmd: Command,
-		body: Option<&Bytes>,
-		caddr: IpAddr,
-		debug: bool,
-		path: &str,
-	) -> CgiResponse {
+	async fn call_and_parse_cgi(mut cmd: Command, body: Option<&Bytes>) -> CgiResponse {
 		let mut response = CgiResponse {
 			// Default status code is 200 per RFC
 			status: 200,
@@ -296,35 +281,26 @@ impl Svc {
 			body: None,
 		};
 
-		println!("!!! before spawn: {path}");
 		let cmd = cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
 		let output = if let Some(bytes) = body {
-			println!("!!! has body len={}", bytes.len());
 			let mut child = cmd.stdin(Stdio::piped()).spawn().unwrap();
 
-			let cmd_stdin = child.stdin.take().unwrap();
-			let mut bufwrite = BufWriter::new(cmd_stdin);
-			bufwrite.write_all(bytes).await.unwrap();
+			let mut cmd_stdin = child.stdin.take().unwrap();
+			cmd_stdin.write_all(bytes).await.unwrap();
 
-			drop(bufwrite);
-			println!("!!! after drop ({path})");
+			// we might not need the explicit flush here, stdin doesn't seem
+			// to require it, but there used to be a BufWriter here instead
+			// and if you drop without a flush the buffered contents are lost,
+			// so it stays because i am traumatized or something.
+			cmd_stdin.flush().await.unwrap();
+			drop(cmd_stdin);
 
 			child.wait_with_output().await.unwrap()
 		} else {
 			cmd.spawn().unwrap().wait_with_output().await.unwrap()
 		};
-		println!("!!! after spawn ({path})");
 
 		let response_raw = output.stdout;
-
-		if debug {
-			std::fs::write(
-				format!("/tmp/{caddr}-gitbackend-{}", path_to_name(path)),
-				&response_raw,
-			)
-			.unwrap();
-		}
-
 		let mut curr = response_raw.as_slice();
 		loop {
 			// Find the newline to know where this header ends
@@ -365,7 +341,6 @@ impl Svc {
 					response.body = Some(body.to_vec());
 				}
 
-				println!("!!! before call_and_parse return ({path})");
 				return response;
 			}