From e816523709ced5da5f9f7a970c547c42db564e54 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 23 Jul 2022 15:26:46 +0100 Subject: [PATCH] Return status properly to client from CGI --- src/methods/repo/smart_git.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/methods/repo/smart_git.rs b/src/methods/repo/smart_git.rs index 67773dd..dc05ccb 100644 --- a/src/methods/repo/smart_git.rs +++ a/src/methods/repo/smart_git.rs @@ -12,8 +12,10 @@ use futures::TryStreamExt; use httparse::Status; use tokio_util::io::StreamReader; +use tracing::warn; use crate::methods::repo::{Repository, RepositoryPath, Result}; +use crate::StatusCode; #[allow(clippy::unused_async)] pub async fn handle( @@ -40,6 +42,7 @@ .env("QUERY_STRING", uri.query().unwrap_or("")) .stdin(Stdio::piped()) .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .context("Failed to spawn git http-backend")?; @@ -59,6 +62,10 @@ .context("Failed to read git http-backend response")?; let resp = cgi_to_response(&out.stdout)?; + if out.stderr.len() > 0 { + warn!("Git returned an error: `{}`", String::from_utf8_lossy(&out.stderr)); + } + Ok(resp) } @@ -91,6 +98,14 @@ HeaderValue::from_bytes(header.value) .context("Failed to parse header value from Git over CGI")?, ); + } + + if let Some(status) = response.headers_mut().remove("Status").filter(|s| s.len() >= 3) { + let status = &status.as_ref()[..3]; + + if let Ok(status) = StatusCode::from_bytes(status) { + *response.status_mut() = status; + } } Ok(response) -- rgit 0.1.3