mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-28 07:20:12 +01:00
Add Redirect::to constructor (#255)
The motivation for this is established in the issue it fixes. Resolves #248
This commit is contained in:
parent
1a5f977896
commit
536b8ca4ec
2 changed files with 25 additions and 1 deletions
|
@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- 👀
|
- **added:** Add `Redirect::to` constructor ([#255](https://github.com/tokio-rs/axum/pull/255))
|
||||||
|
|
||||||
# 0.2.0 (23. August, 2021)
|
# 0.2.0 (23. August, 2021)
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,27 @@ pub struct Redirect {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Redirect {
|
impl Redirect {
|
||||||
|
/// Create a new [`Redirect`] that uses a [`303 See Other`][mdn] 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).
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// If `uri` isn't a valid [`HeaderValue`].
|
||||||
|
///
|
||||||
|
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303
|
||||||
|
pub fn to(uri: Uri) -> Self {
|
||||||
|
Self::with_status_code(StatusCode::SEE_OTHER, uri)
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new [`Redirect`] that uses a [`307 Temporary Redirect`][mdn] status code.
|
/// Create a new [`Redirect`] that uses a [`307 Temporary Redirect`][mdn] status code.
|
||||||
///
|
///
|
||||||
|
/// This has the same behavior as [`Redirect::to`], except it will preserve the original HTTP
|
||||||
|
/// method and body.
|
||||||
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// If `uri` isn't a valid [`HeaderValue`].
|
/// If `uri` isn't a valid [`HeaderValue`].
|
||||||
|
@ -53,6 +72,11 @@ impl Redirect {
|
||||||
|
|
||||||
/// Create a new [`Redirect`] that uses a [`302 Found`][mdn] status code.
|
/// Create a new [`Redirect`] that uses a [`302 Found`][mdn] status code.
|
||||||
///
|
///
|
||||||
|
/// This is the same as [`Redirect::temporary`], except the status code is older and thus
|
||||||
|
/// supported by some legacy applications that doesn't understand the newer one, but some of
|
||||||
|
/// those applications wrongly apply [`Redirect::to`] (`303 See Other`) semantics for this
|
||||||
|
/// status code. It should be avoided where possible.
|
||||||
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// If `uri` isn't a valid [`HeaderValue`].
|
/// If `uri` isn't a valid [`HeaderValue`].
|
||||||
|
|
Loading…
Reference in a new issue