Struct Redirect

struct Redirect { ... }

Response that redirects the request to another location.

Example

use axum::{
    routing::get,
    response::Redirect,
    Router,
};

let app = Router::new()
    .route("/old", get(|| async { Redirect::permanent("/new") }))
    .route("/new", get(|| async { "Hello!" }));
# let _: Router = app;

Implementations

impl Redirect

fn to(uri: &str) -> Self

Create a new Redirect that uses a 303 See Other status code.

This redirect instructs the client to change the method to GET for the subsequent request to the given uri, which is useful after successful form submission, file upload or when you generally don't want the redirected-to page to observe the original request method and body (if non-empty). If you want to preserve the request method and body, Redirect::temporary should be used instead.

Panics

If uri isn't a valid HeaderValue.

fn temporary(uri: &str) -> Self

Create a new Redirect that uses a 307 Temporary Redirect status code.

This has the same behavior as Redirect::to, except it will preserve the original HTTP method and body.

Panics

If uri isn't a valid HeaderValue.

fn permanent(uri: &str) -> Self

Create a new Redirect that uses a 308 Permanent Redirect status code.

Panics

If uri isn't a valid HeaderValue.

impl Clone for Redirect

fn clone(self: &Self) -> Redirect

impl Debug for Redirect

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Freeze for Redirect

impl IntoResponse for Redirect

fn into_response(self: Self) -> Response

impl RefUnwindSafe for Redirect

impl Send for Redirect

impl Sync for Redirect

impl Unpin for Redirect

impl UnsafeUnpin for Redirect

impl UnwindSafe for Redirect

impl<H, T> HandlerWithoutStateExt for Redirect

fn into_service(self: Self) -> HandlerService<H, T, ()>
fn into_make_service(self: Self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service_with_connect_info<C>(self: Self) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>

impl<T> Any for Redirect

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Redirect

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Redirect

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Redirect

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Redirect

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FromRef for Redirect

fn from_ref(input: &T) -> T

impl<T> Instrument for Redirect

impl<T> Same for Redirect

impl<T> ToOwned for Redirect

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> WithSubscriber for Redirect

impl<T, U> Into for Redirect

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Redirect

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Redirect

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<V, T> VZip for Redirect

fn vzip(self: Self) -> V