Skip to content

Commit

Permalink
fix: allow HEAD method for dynamic routes
Browse files Browse the repository at this point in the history
stelae is now able to resolve HEAD method requests.
  • Loading branch information
n-dusan committed Nov 22, 2024
1 parent e5a2f10 commit ac4b26c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/server/api/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ fn register_root_routes(cfg: &mut web::ServiceConfig, stele: &Stele) -> anyhow::
root_scope = root_scope.service(
web::resource(actix_route.as_str())
.route(web::get().to(serve))
.route(web::head().to(serve))
.app_data(web::Data::new(repo_state.clone())),
);
}
Expand All @@ -257,6 +258,7 @@ fn register_root_routes(cfg: &mut web::ServiceConfig, stele: &Stele) -> anyhow::
web::scope("").service(
web::resource("/{tail:.*}")
.route(web::get().to(serve))
.route(web::head().to(serve))
.app_data(web::Data::new(repo_state.clone())),
),
);
Expand Down Expand Up @@ -298,6 +300,7 @@ fn register_dependent_routes(
actix_scope = actix_scope.service(
web::resource(actix_route.as_str())
.route(web::get().to(serve))
.route(web::head().to(serve))
.app_data(web::Data::new(repo_state.clone())),
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/server/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
clippy::infinite_loop
)]

use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
use actix_web::{get, route, web, App, HttpResponse, HttpServer, Responder};
use git2::{self, ErrorCode};
use std::path::PathBuf;
use tracing_actix_web::TracingLogger;
Expand Down Expand Up @@ -43,7 +43,11 @@ async fn misc(path: web::Path<String>) -> actix_web::Result<&'static str, Stelae
/// Return the content in the stelae archive in the `{namespace}/{name}`
/// repo at the `commitish` commit at the `remainder` path.
/// Return 404 if any are not found or there are any errors.
#[get("/{namespace}/{name}/{commitish}{remainder:/+([^{}]*?)?/*}")]
#[route(
"/{namespace}/{name}/{commitish}{remainder:/+([^{}]*?)?/*}",
method = "GET",
method = "HEAD"
)]
#[tracing::instrument(name = "Retrieving a Git blob", skip(path, data))]
async fn get_blob(
path: web::Path<(String, String, String, String)>,
Expand Down

0 comments on commit ac4b26c

Please sign in to comment.