#tower #tower-service #tower-http #http #blocking #security #http-response

tunnelbana-hidepaths

Hide specific paths in tower services by sending them to a 404 service

1 unstable release

0.1.0 Nov 11, 2024

#2070 in Web programming

Download history 158/week @ 2024-11-11 16/week @ 2024-11-18 21/week @ 2024-11-25 24/week @ 2024-12-02 14/week @ 2024-12-09

85 downloads per month
Used in tunnelbana

MIT/Apache

11KB
173 lines

tunnelbana-hidepaths

Hide specific paths in tower services by sending them to a 404 service.

https://docs.rs/tunnelbana-hidepaths


lib.rs:

tunnelbana-hidepaths

Hide specific paths in tower services by sending them to a 404 service.

Part of the tunnelbana project.

Example

use tower_http::services::ServeDir;
use tower::{ServiceBuilder, ServiceExt};
use http::Response;
use tunnelbana_hidepaths::HidePathsLayer;

let hidepaths_middleware = HidePathsLayer::builder()
    .hide("/_redirects")
    .hide_all(["/.htaccess", "/.well-known/{*hide}"])
    .build()
    .expect("Failed to build path hide router");
let serve_dir = ServeDir::new("/var/www/html").append_index_html_on_directories(true);
let service = ServiceBuilder::new()
   .layer(hidepaths_middleware)
   .service(serve_dir);

Dependencies

~2.1–3MB
~54K SLoC