pub struct Redirect { /* private fields */ }Expand description
HTTP redirect response.
Creates responses with appropriate redirect status codes and Location header.
§Examples
use fastapi_core::Redirect;
// Temporary redirect (307)
let response = Redirect::temporary("/new-location");
// Permanent redirect (308)
let response = Redirect::permanent("/moved-permanently");
// See Other (303) - for POST/redirect/GET pattern
let response = Redirect::see_other("/result");Implementations§
Source§impl Redirect
impl Redirect
Sourcepub fn temporary(location: impl Into<String>) -> Self
pub fn temporary(location: impl Into<String>) -> Self
Create a 307 Temporary Redirect.
The request method and body should be preserved when following the redirect.
Sourcepub fn permanent(location: impl Into<String>) -> Self
pub fn permanent(location: impl Into<String>) -> Self
Create a 308 Permanent Redirect.
The request method and body should be preserved when following the redirect. This indicates the resource has permanently moved.
Sourcepub fn see_other(location: impl Into<String>) -> Self
pub fn see_other(location: impl Into<String>) -> Self
Create a 303 See Other redirect.
The client should use GET to fetch the redirected resource. Commonly used for POST/redirect/GET pattern.
Sourcepub fn moved_permanently(location: impl Into<String>) -> Self
pub fn moved_permanently(location: impl Into<String>) -> Self
Create a 301 Moved Permanently redirect.
Note: Browsers may change POST to GET. Use 308 for method preservation.
Sourcepub fn found(location: impl Into<String>) -> Self
pub fn found(location: impl Into<String>) -> Self
Create a 302 Found redirect.
Note: Browsers may change POST to GET. Use 307 for method preservation.
Sourcepub fn status(&self) -> StatusCode
pub fn status(&self) -> StatusCode
Get the status code.
Trait Implementations§
Source§impl IntoResponse for Redirect
impl IntoResponse for Redirect
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert into a response.
Auto Trait Implementations§
impl Freeze for Redirect
impl RefUnwindSafe for Redirect
impl Send for Redirect
impl Sync for Redirect
impl Unpin for Redirect
impl UnwindSafe for Redirect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).