From 746f92f52bb62f731c84b88649c3247b28185aa2 Mon Sep 17 00:00:00 2001 From: gered Date: Tue, 11 Jul 2023 12:12:37 -0400 Subject: [PATCH] allow all routes to also respond to HEAD requests i've noticed that some services out there seem to issue HEAD requests to web sites as part of some sort of metadata fetching process about links contained in content that they are processing (e.g. Mastodon). currently we were just responding with 404's to these because actix does not respond to HEAD requests for any route unless you explicitly set up the request to respond that way (with the sole exception being the default route handler in actix which is invoked for any type of request) --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 819f8b2..dc13ef2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,26 +16,26 @@ fn not_found() -> HttpResponse { HttpResponse::NotFound().body("not found") } -#[actix_web::get("/")] +#[actix_web::route("/", method = "GET", method = "HEAD")] async fn latest_posts(data: web::Data) -> impl Responder { log::debug!("GET / -> latest_posts()"); data.serve_latest_post() } -#[actix_web::get("/tag/{tag}")] +#[actix_web::route("/tag/{tag}", method = "GET", method = "HEAD")] async fn latest_posts_by_tag(path: web::Path<(String,)>, data: web::Data) -> impl Responder { let tag = path.into_inner().0; log::debug!("GET /tag/{0} -> latest_posts_by_tag(), tag = {0}", tag); data.serve_posts_by_tag(&tag) } -#[actix_web::get("/archive")] +#[actix_web::route("/archive", method = "GET", method = "HEAD")] async fn posts_archive(data: web::Data) -> impl Responder { log::debug!("GET /archive -> posts_archive()"); data.serve_posts_archive() } -#[actix_web::get("/rss")] +#[actix_web::route("/rss", method = "GET", method = "HEAD")] async fn rss_feed(data: web::Data) -> impl Responder { log::debug!("GET /rss -> rss_feed()"); data.serve_rss_feed()