@@ -4,7 +4,6 @@ use tide::*;
4
4
async fn test_status ( ) {
5
5
let mut resp = Response :: new ( StatusCode :: NotFound ) . body_string ( "foo" . to_string ( ) ) ;
6
6
assert_eq ! ( resp. status( ) , StatusCode :: NotFound ) ;
7
-
8
7
let foo = resp. take_body ( ) . into_string ( ) . await . unwrap ( ) ;
9
8
assert_eq ! ( foo. as_bytes( ) , b"foo" ) ;
10
9
}
@@ -16,14 +15,12 @@ async fn byte_vec_content_type() {
16
15
use std:: str:: FromStr ;
17
16
18
17
let mut resp = Response :: new ( StatusCode :: Ok ) . body ( Cursor :: new ( "foo" ) ) ;
19
-
20
18
let mut header_values: Vec < HeaderValue > = Vec :: new ( ) ;
21
19
let content_type = HeaderName :: from_str ( "Content-Type" ) . unwrap ( ) ;
22
20
if let Some ( x) = resp. remove_header ( & content_type) {
23
21
header_values = x;
24
22
}
25
23
assert_eq ! ( header_values[ 0 ] , "application/octet-stream" ) ;
26
-
27
24
let foo = resp. take_body ( ) . into_string ( ) . await . unwrap ( ) ;
28
25
assert_eq ! ( foo. as_bytes( ) , b"foo" ) ;
29
26
}
@@ -34,14 +31,12 @@ async fn string_content_type() {
34
31
use std:: str:: FromStr ;
35
32
36
33
let mut resp = Response :: new ( StatusCode :: Ok ) . body_string ( "foo" . to_string ( ) ) ;
37
-
38
34
let mut header_values: Vec < HeaderValue > = Vec :: new ( ) ;
39
35
let content_type = HeaderName :: from_str ( "Content-Type" ) . unwrap ( ) ;
40
36
if let Some ( x) = resp. remove_header ( & content_type) {
41
37
header_values = x;
42
38
}
43
39
assert_eq ! ( header_values[ 0 ] , "text/plain; charset=utf-8" ) ;
44
-
45
40
let foo = resp. take_body ( ) . into_string ( ) . await . unwrap ( ) ;
46
41
assert_eq ! ( foo. as_bytes( ) , b"foo" ) ;
47
42
}
@@ -57,30 +52,24 @@ async fn json_content_type() {
57
52
map. insert ( Some ( "a" ) , 2 ) ;
58
53
map. insert ( Some ( "b" ) , 4 ) ;
59
54
map. insert ( None , 6 ) ;
60
- println ! ( "{:?}" , serde_json:: to_vec( & map) ) ;
61
-
62
55
let resp = Response :: new ( StatusCode :: Ok ) . body_json ( & map) ?;
63
56
Ok ( resp)
64
57
} ) ;
65
-
66
58
let req = http:: Request :: new (
67
59
Method :: Get ,
68
60
"http://localhost/json_content_type" . parse ( ) . unwrap ( ) ,
69
61
) ;
70
62
let mut resp: http:: Response = app. respond ( req) . await . unwrap ( ) ;
71
63
assert_eq ! ( resp. status( ) , StatusCode :: InternalServerError ) ;
72
-
73
64
let body = resp. take_body ( ) . into_string ( ) . await . unwrap ( ) ;
74
65
assert_eq ! ( body. as_bytes( ) , b"" ) ;
75
66
76
67
let mut map = BTreeMap :: new ( ) ;
77
68
map. insert ( "a" , 2 ) ;
78
69
map. insert ( "b" , 4 ) ;
79
70
map. insert ( "c" , 6 ) ;
80
-
81
71
let mut resp = Response :: new ( StatusCode :: Ok ) . body_json ( & map) . unwrap ( ) ;
82
72
assert_eq ! ( resp. status( ) , StatusCode :: Ok ) ;
83
-
84
73
let body = resp. take_body ( ) . into_string ( ) . await . unwrap ( ) ;
85
74
assert_eq ! ( body. as_bytes( ) , br##"{"a":2,"b":4,"c":6}"## ) ;
86
75
}
0 commit comments