@@ -39,7 +39,7 @@ async fn string_content_type() {
39
39
40
40
#[ async_std:: test]
41
41
async fn json_content_type ( ) {
42
- use http_types:: Method ;
42
+ use http_types:: { Method , Url } ;
43
43
use std:: collections:: BTreeMap ;
44
44
45
45
let mut app = tide:: new ( ) ;
@@ -53,18 +53,21 @@ async fn json_content_type() {
53
53
} ) ;
54
54
let req = http:: Request :: new (
55
55
Method :: Get ,
56
- "http://localhost/json_content_type" . parse ( ) . unwrap ( ) ,
56
+ Url :: parse ( "http://localhost/json_content_type" ) . unwrap ( ) ,
57
57
) ;
58
58
let mut resp: http:: Response = app. respond ( req) . await . unwrap ( ) ;
59
59
assert_eq ! ( resp. status( ) , StatusCode :: InternalServerError ) ;
60
60
let body = resp. take_body ( ) . into_string ( ) . await . unwrap ( ) ;
61
61
assert_eq ! ( body. as_bytes( ) , b"" ) ;
62
62
63
- let mut map = BTreeMap :: new ( ) ;
64
- map. insert ( "a" , 2 ) ;
65
- map. insert ( "b" , 4 ) ;
66
- map. insert ( "c" , 6 ) ;
67
- let mut resp = Response :: new ( StatusCode :: Ok ) . body_json ( & map) . unwrap ( ) ;
63
+ let mut resp = async move {
64
+ let mut map = BTreeMap :: new ( ) ;
65
+ map. insert ( "a" , 2 ) ;
66
+ map. insert ( "b" , 4 ) ;
67
+ map. insert ( "c" , 6 ) ;
68
+ Response :: new ( StatusCode :: Ok ) . body_json ( & map) . unwrap ( )
69
+ }
70
+ . await ;
68
71
assert_eq ! ( resp. status( ) , StatusCode :: Ok ) ;
69
72
let body = resp. take_body ( ) . into_string ( ) . await . unwrap ( ) ;
70
73
assert_eq ! ( body. as_bytes( ) , br##"{"a":2,"b":4,"c":6}"## ) ;
0 commit comments