From ee7e115b2d0e6a6eee42eb875199c965696017d5 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 21 Nov 2025 15:35:19 +0000 Subject: fixed http clone but do we really nedd to create a blank commit? I dont think ngit-relay does that. Do we need to se the default branch or is this automatic? --- src/http/mod.rs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/http') diff --git a/src/http/mod.rs b/src/http/mod.rs index 28ccd7b..c676bda 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -14,7 +14,7 @@ use hyper::server::conn::http1; use hyper::service::Service; use hyper::{Method, Request, Response}; use hyper_util::rt::TokioIo; -use http_body_util::BodyExt; +use http_body_util::{BodyExt, Full}; use nostr_sdk::hashes::sha1::Hash as Sha1Hash; use nostr_sdk::hashes::{Hash, HashEngine}; use nostr_relay_builder::LocalRelay; @@ -42,7 +42,7 @@ impl HttpService { } impl Service> for HttpService { - type Response = Response; + type Response = Response>; type Error = String; type Future = Pin> + Send>>; @@ -65,6 +65,11 @@ impl Service> for HttpService { let repo_path = git::resolve_repo_path(&git_data_path, &npub, &identifier); return Box::pin(async move { + // Collect request body once before the match statement + let body_bytes = req.collect().await + .map(|collected| collected.to_bytes()) + .unwrap_or_else(|_| Bytes::new()); + let result = match (method.as_ref(), subpath.as_str()) { // GET /info/refs?service=git-upload-pack or git-receive-pack (m, sp) if m == Method::GET && sp.starts_with("info/refs") => { @@ -85,22 +90,12 @@ impl Service> for HttpService { // POST /git-upload-pack (clone/fetch) (m, "git-upload-pack") if m == Method::POST => { - // Read request body - let body_bytes = req.collect().await - .map(|collected| collected.to_bytes()) - .unwrap_or_else(|_| Bytes::new()); - git::handlers::handle_upload_pack(repo_path, body_bytes).await } // POST /git-receive-pack (push) (m, "git-receive-pack") if m == Method::POST => { - // Read request body - let body_bytes = req.collect().await - .map(|collected| collected.to_bytes()) - .unwrap_or_else(|_| Bytes::new()); - - git::handlers::handle_receive_pack(repo_path, body_bytes).await + git::handlers::handle_receive_pack(repo_path, body_bytes.clone()).await } _ => { @@ -112,9 +107,10 @@ impl Service> for HttpService { Ok(response) => Ok(response), Err(e) => { tracing::error!("Git handler error: {}", e); + let error_msg = format!("Git error: {}", e); Ok(Response::builder() .status(e.status_code()) - .body(format!("Git error: {}", e)) + .body(Full::new(Bytes::from(error_msg))) .unwrap()) } } @@ -141,7 +137,7 @@ impl Service> for HttpService { .status(200) .header("content-type", "application/nostr+json") .header("access-control-allow-origin", "*") - .body(json) + .body(Full::new(Bytes::from(json))) .unwrap()) }); } @@ -185,7 +181,7 @@ impl Service> for HttpService { .header(CONNECTION, "upgrade") .header(UPGRADE, "websocket") .header(SEC_WEBSOCKET_ACCEPT, derived.unwrap()) - .body("".to_string()) + .body(Full::new(Bytes::new())) .unwrap()) }); } @@ -197,7 +193,7 @@ impl Service> for HttpService { Ok(base .status(200) .header("content-type", "text/html; charset=utf-8") - .body(html) + .body(Full::new(Bytes::from(html))) .unwrap()) }) } -- cgit v1.2.3