This is supported on crate feature redirect only.
Expand description

Service that redirects all requests.

Example

Imagine that we run example.com and want to redirect all requests using HTTP to HTTPS. That can be done like so:

use http::{Request, Uri, StatusCode};
use hyper::Body;
use tower::{Service, ServiceExt};
use tower_http::services::Redirect;

let uri: Uri = "https://example.com/".parse().unwrap();
let mut service: Redirect<Body> = Redirect::permanent(uri);

let request = Request::builder()
    .uri("http://example.com")
    .body(Body::empty())
    .unwrap();

let response = service.oneshot(request).await?;

assert_eq!(response.status(), StatusCode::PERMANENT_REDIRECT);
assert_eq!(response.headers()["location"], "https://example.com/");

Structs

Service that redirects all requests.

Response future of Redirect.