#cache #tower #serve #tower-service #static #etags

tunnelbana-etags

Generate etags for static files and serve them with tower

1 unstable release

new 0.1.0 Nov 11, 2024

#137 in Caching

Download history 129/week @ 2024-11-08

129 downloads per month
Used in tunnelbana

MIT/Apache

15KB
291 lines

tunnelbana-etags

Generate etags for static files and serve them with tower.

https://docs.rs/tunnelbana-etags


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