22
33use serde:: Serialize ;
44use viz:: {
5- header:: { HeaderValue , SERVER } ,
6- Bytes , Error , Request , Response , ResponseExt , Result , Router ,
5+ header:: { HeaderValue , CONTENT_TYPE , SERVER } ,
6+ Body , Bytes , Error , Request , Response , ResponseExt , Result , Router ,
77} ;
88
99mod server;
@@ -22,18 +22,24 @@ async fn plaintext(_: Request) -> Result<Response> {
2222}
2323
2424async fn json ( _: Request ) -> Result < Response > {
25- let mut res = Response :: with (
26- http_body_util:: Full :: new ( Bytes :: from (
27- serde_json:: to_vec ( & Message {
28- message : "Hello, World!" ,
29- } )
30- . unwrap ( ) ,
31- ) ) ,
32- mime:: APPLICATION_JSON . as_ref ( ) ,
25+ let mut resp = Response :: builder ( )
26+ . body (
27+ http_body_util:: Full :: new ( Bytes :: from (
28+ serde_json:: to_vec ( & Message {
29+ message : "Hello, World!" ,
30+ } )
31+ . unwrap ( ) ,
32+ ) )
33+ . into ( ) ,
34+ )
35+ . unwrap ( ) ;
36+ let headers = resp. headers_mut ( ) ;
37+ headers. insert ( SERVER , HeaderValue :: from_static ( "Viz" ) ) ;
38+ headers. insert (
39+ CONTENT_TYPE ,
40+ HeaderValue :: from_static ( mime:: APPLICATION_JSON . as_ref ( ) ) ,
3341 ) ;
34- res. headers_mut ( )
35- . insert ( SERVER , HeaderValue :: from_static ( "Viz" ) ) ;
36- Ok ( res)
42+ Ok ( resp)
3743}
3844
3945#[ tokio:: main]
0 commit comments