🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-23 15:26:46.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-23 15:26:46.0 +01:00:00
commit
e816523709ced5da5f9f7a970c547c42db564e54 [patch]
tree
e9606cb95eb31eb8419ceb4cfc51b4d575224ada
parent
149a87f0619078331537f0e9b8386ac34fd51c04
download
e816523709ced5da5f9f7a970c547c42db564e54.tar.gz

Return status properly to client from CGI



Diff

 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)