Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow HEAD method for dynamic routes #58

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading