File tree Expand file tree Collapse file tree 1 file changed +11
-17
lines changed Expand file tree Collapse file tree 1 file changed +11
-17
lines changed Original file line number Diff line number Diff line change @@ -258,14 +258,18 @@ impl Into<http::Response> for Response {
258
258
}
259
259
}
260
260
261
+ impl From < http:: Body > for Response {
262
+ fn from ( body : http:: Body ) -> Self {
263
+ let mut res = Response :: new ( 200 ) ;
264
+ res. set_body ( body) ;
265
+ res
266
+ }
267
+ }
268
+
261
269
impl From < serde_json:: Value > for Response {
262
270
fn from ( json_value : serde_json:: Value ) -> Self {
263
271
Body :: from_json ( & json_value)
264
- . map ( |body| {
265
- let mut res = Response :: new ( 200 ) ;
266
- res. set_body ( body) ;
267
- res
268
- } )
272
+ . map ( |body| body. into ( ) )
269
273
. unwrap_or_else ( |_| Response :: new ( StatusCode :: InternalServerError ) )
270
274
}
271
275
}
@@ -281,23 +285,13 @@ impl From<http::Response> for Response {
281
285
282
286
impl From < String > for Response {
283
287
fn from ( s : String ) -> Self {
284
- let mut res = http_types:: Response :: new ( StatusCode :: Ok ) ;
285
- res. set_body ( s) ;
286
- Self {
287
- res,
288
- cookie_events : vec ! [ ] ,
289
- }
288
+ Body :: from_string ( s) . into ( )
290
289
}
291
290
}
292
291
293
292
impl < ' a > From < & ' a str > for Response {
294
293
fn from ( s : & ' a str ) -> Self {
295
- let mut res = http_types:: Response :: new ( StatusCode :: Ok ) ;
296
- res. set_body ( String :: from ( s) ) ;
297
- Self {
298
- res,
299
- cookie_events : vec ! [ ] ,
300
- }
294
+ Body :: from_string ( String :: from ( s) ) . into ( )
301
295
}
302
296
}
303
297
You can’t perform that action at this time.
0 commit comments