From b0cf401350321d5ecd000392ba923112656d30d1 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Sat, 9 Dec 2023 11:54:02 +0100 Subject: [PATCH] feat: add rejecting git connection if `enable_http_clone` is `false` --- src/methods/repo/smart_git.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/methods/repo/smart_git.rs b/src/methods/repo/smart_git.rs index 5e04345..001527d 100644 --- a/src/methods/repo/smart_git.rs +++ b/src/methods/repo/smart_git.rs @@ -23,6 +23,7 @@ use tokio_util::io::StreamReader; use tracing::{debug, error, info_span, warn, Instrument}; use crate::{ + configuration::AppConfig, methods::repo::{Repository, RepositoryPath, Result}, StatusCode, }; @@ -31,11 +32,22 @@ use crate::{ pub async fn handle( Extension(RepositoryPath(repository_path)): Extension, Extension(Repository(repository)): Extension, + Extension(config): Extension, method: Method, uri: Uri, headers: HeaderMap, body: Body, ) -> Result { + if !config.http_clone_enabled() { + let headers = Response::builder() + .status(StatusCode::SERVICE_UNAVAILABLE) + .body(()) + .context("error forming response when `enable_http_clone` is `false`")?; + let body = Body::from("HTTP(s) clone is not enabled on this server."); + + return Ok((headers, body)); + } + let path = extract_path(&uri, &repository)?; let mut command = Command::new("git"); -- libgit2 1.7.2