2 releases
0.1.1 | Nov 11, 2024 |
---|---|
0.1.0 | Nov 11, 2024 |
#1985 in Web programming
104 downloads per month
Used in tunnelbana
11KB
183 lines
tunnelbana-headers
Generate headers from _headers text files and serve them with tower.
lib.rs
:
tunnelbana-headers
A tower middleware to add headers to specific routes, or route groups.
Part of the tunnelbana project.
Example
use tower_http::services::ServeDir;
use tower::{ServiceBuilder, ServiceExt};
use http::Response;
use tunnelbana_headers::HeadersLayer;
let config = r#"
/example
X-Example-Header: example.org
/subpath/{other}
X-Header-One: h1
X-Header-Two: h2
/wildcard/{*wildcard}
X-Header-A: ha
X-Header-B: hb
"#;
let headers = tunnelbana_headers::parse(config).expect("Failed to parse headers");
let headers_mw = HeadersLayer::new(headers).expect("Failed to route headers");
let serve_dir = ServeDir::new("/var/www/html").append_index_html_on_directories(true);
let service = ServiceBuilder::new()
.layer(headers_mw)
.service(serve_dir);
Dependencies
~1.6–2.3MB
~41K SLoC