diff --git a/radicle-httpd/src/api.rs b/radicle-httpd/src/api.rs index 4f89da50..848fdef5 100644 --- a/radicle-httpd/src/api.rs +++ b/radicle-httpd/src/api.rs @@ -21,7 +21,6 @@ use radicle::identity::Id; use radicle::storage::{ReadRepository, ReadStorage}; use radicle::Profile; -mod axum_extra; mod error; mod json; mod v1; diff --git a/radicle-httpd/src/api/v1/delegates.rs b/radicle-httpd/src/api/v1/delegates.rs index 52fa5ca5..530dc76d 100644 --- a/radicle-httpd/src/api/v1/delegates.rs +++ b/radicle-httpd/src/api/v1/delegates.rs @@ -8,11 +8,11 @@ use radicle::cob::patch::Patches; use radicle::identity::Did; use radicle::storage::{ReadRepository, ReadStorage}; -use crate::api::axum_extra::{Path, Query}; use crate::api::error::Error; use crate::api::project::Info; use crate::api::Context; use crate::api::PaginationQuery; +use crate::axum_extra::{Path, Query}; pub fn router(ctx: Context) -> Router { Router::new() diff --git a/radicle-httpd/src/api/v1/projects.rs b/radicle-httpd/src/api/v1/projects.rs index d768a3e4..1bde6fee 100644 --- a/radicle-httpd/src/api/v1/projects.rs +++ b/radicle-httpd/src/api/v1/projects.rs @@ -17,13 +17,14 @@ use radicle::cob::patch::Patches; use radicle::cob::{thread, ActorId, Tag}; use radicle::identity::Id; use radicle::node::NodeId; -use radicle::storage::{git::paths, ReadRepository, ReadStorage}; +use radicle::storage::git::paths; +use radicle::storage::{ReadRepository, ReadStorage}; use radicle_surf::{Glob, Oid, Repository}; -use crate::api::axum_extra::{Path, Query}; use crate::api::error::Error; use crate::api::project::Info; use crate::api::{self, Context, PaginationQuery}; +use crate::axum_extra::{Path, Query}; const CACHE_1_HOUR: &str = "public, max-age=3600, must-revalidate"; diff --git a/radicle-httpd/src/api/v1/sessions.rs b/radicle-httpd/src/api/v1/sessions.rs index c1e2146b..340951fb 100644 --- a/radicle-httpd/src/api/v1/sessions.rs +++ b/radicle-httpd/src/api/v1/sessions.rs @@ -11,10 +11,10 @@ use serde::{Deserialize, Serialize}; use time::OffsetDateTime; use crate::api::auth::{self, AuthState, Session}; -use crate::api::axum_extra::Path; use crate::api::error::Error; use crate::api::json; use crate::api::Context; +use crate::axum_extra::Path; pub fn router(ctx: Context) -> Router { Router::new() diff --git a/radicle-httpd/src/api/axum_extra.rs b/radicle-httpd/src/axum_extra.rs similarity index 100% rename from radicle-httpd/src/api/axum_extra.rs rename to radicle-httpd/src/axum_extra.rs diff --git a/radicle-httpd/src/error.rs b/radicle-httpd/src/error.rs index 1bee5d9e..a722aa8e 100644 --- a/radicle-httpd/src/error.rs +++ b/radicle-httpd/src/error.rs @@ -31,6 +31,10 @@ pub enum Error { /// HeaderValue error. #[error(transparent)] InvalidHeaderValue(#[from] axum::http::header::InvalidHeaderValue), + + /// Surf error. + #[error(transparent)] + Surf(#[from] radicle_surf::Error), } impl Error { diff --git a/radicle-httpd/src/lib.rs b/radicle-httpd/src/lib.rs index 29dd01ad..f69bf097 100644 --- a/radicle-httpd/src/lib.rs +++ b/radicle-httpd/src/lib.rs @@ -16,7 +16,9 @@ use tower_http::trace::TraceLayer; use tracing::Span; mod api; +mod axum_extra; mod git; +mod raw; #[cfg(test)] mod test; @@ -41,13 +43,15 @@ pub async fn run(options: Options) -> anyhow::Result<()> { let ctx = api::Context::new(profile.clone()); let api_router = api::router(ctx); - let git_router = git::router(profile); + let git_router = git::router(profile.clone()); + let raw_router = raw::router(profile); tracing::info!("listening on http://{}", options.listen); let app = Router::new() .merge(git_router) .nest("/api", api_router) + .nest("/raw", raw_router) .layer( TraceLayer::new_for_http() .make_span_with(|request: &Request
| { diff --git a/radicle-httpd/src/raw.rs b/radicle-httpd/src/raw.rs new file mode 100644 index 00000000..648defc9 --- /dev/null +++ b/radicle-httpd/src/raw.rs @@ -0,0 +1,59 @@ +use std::sync::Arc; + +use axum::extract::State; +use axum::http::header; +use axum::response::IntoResponse; +use axum::routing::get; +use axum::Router; +use hyper::HeaderMap; + +use radicle::prelude::Id; +use radicle::profile::Profile; +use radicle::storage::git::paths; +use radicle_surf::{Oid, Repository}; + +use crate::axum_extra::Path; +use crate::error::Error; + +pub fn router(profile: Arc