@@ -30,10 +30,13 @@ fn json(_: HttpRequest<State>) -> Result<HttpResponse> {
30
30
let message = models:: Message {
31
31
message : "Hello, World!"
32
32
} ;
33
+ let body = serde_json:: to_string ( & message) ?;
34
+
33
35
Ok ( httpcodes:: HTTPOk
34
36
. build ( )
35
37
. header ( header:: SERVER , "Actix" )
36
- . json ( message) ?)
38
+ . content_type ( "application/json" )
39
+ . body ( body) ?)
37
40
}
38
41
39
42
fn plaintext ( _: HttpRequest < State > ) -> Result < HttpResponse > {
@@ -48,10 +51,13 @@ fn world_row(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Err
48
51
. from_err ( )
49
52
. and_then ( |res| {
50
53
match res {
51
- Ok ( row) => Ok (
52
- httpcodes:: HTTPOk . build ( )
53
- . header ( header:: SERVER , "Actix" )
54
- . json ( row) ?) ,
54
+ Ok ( row) => {
55
+ let body = serde_json:: to_string ( & row) . unwrap ( ) ;
56
+ Ok ( httpcodes:: HTTPOk . build ( )
57
+ . header ( header:: SERVER , "Actix" )
58
+ . content_type ( "application/json" )
59
+ . body ( body) ?)
60
+ } ,
55
61
Err ( _) =>
56
62
Ok ( httpcodes:: HTTPInternalServerError . into ( ) ) ,
57
63
}
@@ -81,12 +87,14 @@ fn queries(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error
81
87
Err ( e) => Err ( e)
82
88
}
83
89
)
84
- . and_then ( |res|
90
+ . and_then ( |res| {
91
+ let body = serde_json:: to_string ( & res) . unwrap ( ) ;
85
92
Ok ( httpcodes:: HTTPOk . build ( )
86
93
. header ( header:: SERVER , "Actix" )
94
+ . content_type ( "application/json" )
87
95
. content_encoding ( headers:: ContentEncoding :: Identity )
88
- . json ( res ) ?)
89
- )
96
+ . body ( body ) ?)
97
+ } )
90
98
. responder ( )
91
99
}
92
100
@@ -159,8 +167,8 @@ fn fortune(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error
159
167
160
168
Ok ( httpcodes:: HTTPOk . build ( )
161
169
. header ( header:: SERVER , "Actix" )
162
- . content_encoding ( headers:: ContentEncoding :: Identity )
163
170
. content_type ( "text/html; charset=utf-8" )
171
+ . content_encoding ( headers:: ContentEncoding :: Identity )
164
172
. body ( res) ?)
165
173
} ,
166
174
Err ( _) => Ok ( httpcodes:: HTTPInternalServerError . into ( ) )
@@ -169,11 +177,8 @@ fn fortune(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error
169
177
. responder ( )
170
178
}
171
179
172
- use std:: env;
173
180
fn main ( ) {
174
181
let sys = System :: new ( "techempower" ) ;
175
- env:: set_var ( "RUST_BACKTRACE" , "1" ) ;
176
-
177
182
let dbhost = match option_env ! ( "DBHOST" ) {
178
183
Some ( it) => it,
179
184
_ => "127.0.0.1"
0 commit comments