Struct poem::web::Redirect [−][src]
pub struct Redirect { /* fields omitted */ }
Expand description
A redirect response.
Example
use poem::{
get, handler,
http::{header, HeaderValue, StatusCode, Uri},
web::Redirect,
Endpoint, Request, Route,
};
#[handler]
async fn index() -> Redirect {
Redirect::moved_permanent(Uri::from_static("https://www.google.com"))
}
let app = Route::new().at("/", get(index));
let resp = app.call(Request::default()).await.unwrap();
assert_eq!(resp.status(), StatusCode::MOVED_PERMANENTLY);
assert_eq!(
resp.headers().get(header::LOCATION),
Some(&HeaderValue::from_static("https://www.google.com/"))
);
Implementations
A simple 301
permanent redirect to a different location.
Trait Implementations
Consume itself and return Response
.
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self> where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Self: Sized,
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self> where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Self: Sized,
Wrap an impl IntoResponse
to add a header. Read more
Wrap an impl IntoResponse
to set a status code. Read more
Auto Trait Implementations
impl RefUnwindSafe for Redirect
impl UnwindSafe for Redirect
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
Consumes this value returns a poem::Result<T>
.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more