Crate tunnelbana_headers

Crate tunnelbana_headers 

Source
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§

HeaderGroup
HeaderParseError
Describes the location and type of a header parsing problem.
Headers
a tower::Service which adds headers to a wrapped S.
HeadersLayer
a tower::Layer to add to a tower::ServiceBuilder to add headers.
ResponseFuture
Custom future which adds headers unconditionally to a response.

Enums§

HeaderParseErrorKind
Types of header parsing errors. These can come from the http crate, or internally from tunnelbana-headers.
InsertError
Represents errors that can occur when inserting a new route.

Functions§

parse
Parse a list of HeaderGroups from a cloudflare-style _headers string.