Skip to content

Commit 66c9929

Browse files
committed
Add Redirect::found
1 parent 0f9bcb3 commit 66c9929

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/redirect.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ pub struct Redirect<T: AsRef<str>> {
2828
}
2929

3030
impl<T: AsRef<str>> Redirect<T> {
31+
/// Creates an endpoint that represents a found redirect to `location`.
32+
///
33+
/// # Example
34+
///
35+
/// ```
36+
/// # use tide::{Response, Redirect, Request, StatusCode};
37+
/// # fn next_product() -> Option<String> { None }
38+
/// # #[allow(dead_code)]
39+
/// async fn route_handler(request: Request<()>) -> tide::Result {
40+
/// if let Some(product_url) = next_product() {
41+
/// Ok(Redirect::found(product_url).into())
42+
/// } else {
43+
/// //...
44+
/// # Ok(Response::new(StatusCode::Ok)) //...
45+
/// }
46+
/// }
47+
/// ```
48+
pub fn found(location: T) -> Self {
49+
Self {
50+
status: StatusCode::SeeOther,
51+
location,
52+
}
53+
}
54+
3155
/// Creates an endpoint that represents a permanent redirect to `location`.
3256
///
3357
///

0 commit comments

Comments
 (0)