@@ -97,15 +97,42 @@ where
97
97
}
98
98
99
99
impl < T : AsRef < str > > From < Redirect < T > > for Response {
100
- fn from ( redirect : Redirect < T > ) -> Response {
101
- redirect. into ( )
100
+ fn from ( redirect : Redirect < T > ) -> Self {
101
+ Response :: builder ( redirect. status )
102
+ . header ( LOCATION , redirect. location . as_ref ( ) )
103
+ . build ( )
102
104
}
103
105
}
104
106
105
107
impl < T : AsRef < str > > From < & Redirect < T > > for Response {
106
108
fn from ( redirect : & Redirect < T > ) -> Response {
107
- let mut res = Response :: new ( redirect. status ) ;
108
- res. insert_header ( LOCATION , redirect. location . as_ref ( ) ) ;
109
- res
109
+ Response :: builder ( redirect. status )
110
+ . header ( LOCATION , redirect. location . as_ref ( ) )
111
+ . build ( )
112
+ }
113
+ }
114
+
115
+ #[ cfg( test) ]
116
+ mod test {
117
+ use super :: * ;
118
+ use crate :: * ;
119
+
120
+ #[ test]
121
+ fn smoke ( ) {
122
+ let redirect = Redirect :: new ( "https://example.com" ) ;
123
+ let res: Response = redirect. clone ( ) . into ( ) ;
124
+ assert_eq ! ( res. status( ) , StatusCode :: Found ) ;
125
+
126
+ let redirect = Redirect :: temporary ( "https://example.com" ) ;
127
+ let res: Response = redirect. clone ( ) . into ( ) ;
128
+ assert_eq ! ( res. status( ) , StatusCode :: TemporaryRedirect ) ;
129
+
130
+ let redirect = Redirect :: permanent ( "https://example.com" ) ;
131
+ let res: Response = redirect. clone ( ) . into ( ) ;
132
+ assert_eq ! ( res. status( ) , StatusCode :: PermanentRedirect ) ;
133
+
134
+ let redirect = Redirect :: see_other ( "https://example.com" ) ;
135
+ let res: Response = redirect. clone ( ) . into ( ) ;
136
+ assert_eq ! ( res. status( ) , StatusCode :: SeeOther ) ;
110
137
}
111
138
}
0 commit comments