Skip to content

Commit dd4436f

Browse files
committed
impl Response::redirect_see_other
1 parent 0bd964a commit dd4436f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/response.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,30 @@ impl Response {
9393
.set_header("location".parse().unwrap(), location)
9494
}
9595

96+
/// Creates a response that represents a see other redirect to `location`.
97+
///
98+
/// GET methods are unchanged.
99+
/// Other methods are changed to GET and their body lost.
100+
///
101+
/// # Example
102+
///
103+
/// ```
104+
/// # use tide::{Response, Request, StatusCode};
105+
/// # fn next_product() -> Option<String> { None }
106+
/// # #[allow(dead_code)]
107+
/// async fn route_handler(request: Request<()>) -> tide::Result {
108+
/// if let Some(product_url) = next_product() {
109+
/// Ok(Response::redirect_see_other(product_url))
110+
/// } else {
111+
/// //...
112+
/// # Ok(Response::new(StatusCode::Ok)) //...
113+
/// }
114+
/// }
115+
/// ```
116+
pub fn redirect_see_other(location: impl AsRef<str>) -> Self {
117+
Response::new(StatusCode::SeeOther).set_header("location".parse().unwrap(), location)
118+
}
119+
96120
/// Returns the statuscode.
97121
pub fn status(&self) -> crate::StatusCode {
98122
self.res.status()

0 commit comments

Comments
 (0)