Expand description
§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);Structs§
- Header
Group - Header
Parse Error - Describes the location and type of a header parsing problem.
- Headers
- a
tower::Servicewhich adds headers to a wrapped S. - Headers
Layer - a
tower::Layerto add to atower::ServiceBuilderto add headers. - Response
Future - Custom future which adds headers unconditionally to a response.
Enums§
- Header
Parse Error Kind - Types of header parsing errors. These can come from the
httpcrate, or internally fromtunnelbana-headers. - Insert
Error - Represents errors that can occur when inserting a new route.
Functions§
- parse
- Parse a list of
HeaderGroups from a cloudflare-style _headers string.