Crate tunnelbana_redirects

Crate tunnelbana_redirects 

Source
Expand description

§tunnelbana-redirects

Generate redirect lists from cloudflare-style _redirects text files and serve them with tower.

Part of the tunnelbana project.

§Example

use tower_http::services::ServeDir;
use tower::{ServiceBuilder, ServiceExt};
use http::Response;
use tunnelbana_redirects::RedirectsLayer;

let config = r#"
/example https://example.com 302
/subpath/{other}/final /{other}/final/ 302
/wildcard/{*wildcard} /{wildcard}
"#;
let redirects = tunnelbana_redirects::parse(config).expect("Failed to parse redirects");
let redirects_mw = RedirectsLayer::new(redirects).expect("Failed to route redirects");
let serve_dir = ServeDir::new("/var/www/html").append_index_html_on_directories(true);
let service = ServiceBuilder::new()
   .layer(redirects_mw)
   .service(serve_dir);

Structs§

Redirect
A representation of a redirect, with where it should go and its triggers.
RedirectParseError
Error struct for unparsable redirects. Includes line number and type of error.
Redirects
a tower::Service to add redirects to a wrapped service.
RedirectsLayer
a tower::Layer to add to a tower::ServiceBuilder to add redirects.

Enums§

InsertError
Represents errors that can occur when inserting a new route.
RedirectParseErrorKind
Types of errors that can happen, e.g. wrong number of items on a row, unparsable status code.
ResponseFuture
Future type which can return an unmodified request, a redirect, or an error if a value in the path capture is not a valid header value.

Functions§

parse
Parse a list of Redirects from a cloudflare-style _redirects string.