use axum::http::{StatusCode, header}; use axum::response::{IntoResponse, Response}; use bytes::Bytes; use crate::smart::error::{SmartError, SmartResult}; use crate::smart::pktline; use crate::smart::rpc::{self, GitService}; pub async fn smart_advertisement( bare: &std::path::Path, service: GitService, timeout_secs: u64, ) -> SmartResult { let output = rpc::run_rpc_bytes(bare, service, true, Bytes::new(), timeout_secs).await?; let mut body = pktline::encode_header(service.dashed_name())?; body.extend_from_slice(&output); tracing::debug!( svc = service.name(), bare = %bare.display(), body_bytes = body.len(), "smart ref advertisement generated" ); Ok(( StatusCode::OK, [ (header::CONTENT_TYPE, service.advertisement_content_type()), (header::CACHE_CONTROL, "no-cache"), ], body, ) .into_response()) } pub async fn dumb_info_refs(bare: &std::path::Path) -> SmartResult { let file = bare.join("info").join("refs"); match tokio::fs::read(&file).await { Ok(bytes) => Ok(( StatusCode::OK, [(header::CONTENT_TYPE, "text/plain; charset=utf-8")], bytes, ) .into_response()), Err(e) if e.kind() == std::io::ErrorKind::NotFound => { Err(SmartError::NotFound("info/refs not found".into())) } Err(e) => Err(SmartError::Io(e)), } }