1 unstable release
new 0.1.0 | Nov 11, 2024 |
---|
#137 in Caching
129 downloads per month
Used in tunnelbana
15KB
291 lines
tunnelbana-etags
Generate etags for static files and serve them with tower.
lib.rs
:
tunnelbana-etags
An ETag
adding middleware
for Rust and especially ServeDir
Part of the tunnelbana project.
Example
use http_body_util::combinators::UnsyncBoxBody;
use tower_http::services::ServeDir;
use tower::{ServiceBuilder, ServiceExt};
use http::Response;
use tunnelbana_etags::{ETagLayer, ETagMap};
let path = std::path::PathBuf::from("/var/www/html");
let etags = ETagMap::new(&path).expect("Failed to generate etags");
let etag_mw = ETagLayer::new(etags);
let serve_dir = ServeDir::new(path).append_index_html_on_directories(true);
let service = ServiceBuilder::new()
.layer(etag_mw)
.service(serve_dir);
Dependencies
~5.5MB
~111K SLoC