@@ -21,6 +21,22 @@ use crate::StatusCode;
21
21
use crate :: { Endpoint , Request , Response } ;
22
22
23
23
/// A redirection endpoint.
24
+ ///
25
+ /// # Example
26
+ ///
27
+ /// ```
28
+ /// # use tide::{Response, Redirect, Request, StatusCode};
29
+ /// # fn next_product() -> Option<String> { None }
30
+ /// # #[allow(dead_code)]
31
+ /// async fn route_handler(request: Request<()>) -> tide::Result {
32
+ /// if let Some(product_url) = next_product() {
33
+ /// Ok(Redirect::new(product_url).into())
34
+ /// } else {
35
+ /// //...
36
+ /// # Ok(Response::new(StatusCode::Ok)) //...
37
+ /// }
38
+ /// }
39
+ /// ```
24
40
#[ derive( Debug , Clone ) ]
25
41
pub struct Redirect < T : AsRef < str > > {
26
42
status : StatusCode ,
@@ -31,22 +47,6 @@ impl<T: AsRef<str>> Redirect<T> {
31
47
/// Creates an endpoint that represents a redirect to `location`.
32
48
///
33
49
/// Uses status code 302 Found.
34
- ///
35
- /// # Example
36
- ///
37
- /// ```
38
- /// # use tide::{Response, Redirect, Request, StatusCode};
39
- /// # fn next_product() -> Option<String> { None }
40
- /// # #[allow(dead_code)]
41
- /// async fn route_handler(request: Request<()>) -> tide::Result {
42
- /// if let Some(product_url) = next_product() {
43
- /// Ok(Redirect::new(product_url).into())
44
- /// } else {
45
- /// //...
46
- /// # Ok(Response::new(StatusCode::Ok)) //...
47
- /// }
48
- /// }
49
- /// ```
50
50
pub fn new ( location : T ) -> Self {
51
51
Self {
52
52
status : StatusCode :: SeeOther ,
@@ -56,22 +56,7 @@ impl<T: AsRef<str>> Redirect<T> {
56
56
57
57
/// Creates an endpoint that represents a permanent redirect to `location`.
58
58
///
59
- ///
60
- /// # Example
61
- ///
62
- /// ```
63
- /// # use tide::{Response, Redirect, Request, StatusCode};
64
- /// # fn canonicalize(uri: &url::Url) -> Option<&url::Url> { None }
65
- /// # #[allow(dead_code)]
66
- /// async fn route_handler(request: Request<()>) -> tide::Result {
67
- /// if let Some(canonical_redirect) = canonicalize(request.uri()) {
68
- /// Ok(Redirect::permanent(canonical_redirect).into())
69
- /// } else {
70
- /// //...
71
- /// # Ok(Response::new(StatusCode::Ok)) // ...
72
- /// }
73
- /// }
74
- /// ```
59
+ /// Uses status code 301 Permanent Redirect.
75
60
pub fn permanent ( location : T ) -> Self {
76
61
Self {
77
62
status : StatusCode :: PermanentRedirect ,
@@ -81,22 +66,7 @@ impl<T: AsRef<str>> Redirect<T> {
81
66
82
67
/// Creates an endpoint that represents a temporary redirect to `location`.
83
68
///
84
- ///
85
- /// # Example
86
- ///
87
- /// ```
88
- /// # use tide::{Response, Redirect, Request, StatusCode};
89
- /// # fn special_sale_today() -> Option<String> { None }
90
- /// # #[allow(dead_code)]
91
- /// async fn route_handler(request: Request<()>) -> tide::Result {
92
- /// if let Some(sale_url) = special_sale_today() {
93
- /// Ok(Redirect::temporary(sale_url).into())
94
- /// } else {
95
- /// //...
96
- /// # Ok(Response::new(StatusCode::Ok)) //...
97
- /// }
98
- /// }
99
- /// ```
69
+ /// Uses status code 307 Temporary Redirect.
100
70
pub fn temporary ( location : T ) -> Self {
101
71
Self {
102
72
status : StatusCode :: TemporaryRedirect ,
@@ -106,24 +76,7 @@ impl<T: AsRef<str>> Redirect<T> {
106
76
107
77
/// Creates an endpoint that represents a see other redirect to `location`.
108
78
///
109
- /// GET methods are unchanged.
110
- /// Other methods are changed to GET and their body lost.
111
- ///
112
- /// # Example
113
- ///
114
- /// ```
115
- /// # use tide::{Response, Redirect, Request, StatusCode};
116
- /// # fn next_product() -> Option<String> { None }
117
- /// # #[allow(dead_code)]
118
- /// async fn route_handler(request: Request<()>) -> tide::Result {
119
- /// if let Some(product_url) = next_product() {
120
- /// Ok(Redirect::see_other(product_url).into())
121
- /// } else {
122
- /// //...
123
- /// # Ok(Response::new(StatusCode::Ok)) //...
124
- /// }
125
- /// }
126
- /// ```
79
+ /// Uses status code 303 See Other.
127
80
pub fn see_other ( location : T ) -> Self {
128
81
Self {
129
82
status : StatusCode :: SeeOther ,
0 commit comments