File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,30 @@ impl Response {
93
93
. set_header ( "location" . parse ( ) . unwrap ( ) , location)
94
94
}
95
95
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
+
96
120
/// Returns the statuscode.
97
121
pub fn status ( & self ) -> crate :: StatusCode {
98
122
self . res . status ( )
You can’t perform that action at this time.
0 commit comments