File tree Expand file tree Collapse file tree 4 files changed +41
-14
lines changed
frameworks/Rust/hyperlane/src Expand file tree Collapse file tree 4 files changed +41
-14
lines changed Original file line number Diff line number Diff line change 1+ #[ allow( warnings) ]
2+ #[ allow( dead_code) ]
13pub ( crate ) mod r#const;
24pub ( crate ) mod db;
35pub ( crate ) mod lazy;
@@ -20,6 +22,7 @@ pub(crate) use hyperlane::{
2022pub ( crate ) use lazy:: * ;
2123pub ( crate ) use rand:: { Rng , SeedableRng , rng, rngs:: SmallRng } ;
2224pub ( crate ) use request_middleware:: * ;
25+ #[ allow( unused_imports) ]
2326pub ( crate ) use route:: * ;
2427pub ( crate ) use server:: * ;
2528pub ( crate ) use sqlx:: {
Original file line number Diff line number Diff line change 11use crate :: * ;
22
33pub async fn request ( ctx : Context ) {
4- let _ = ctx
5- . set_response_header ( CONNECTION , CONNECTION_KEEP_ALIVE )
6- . await
7- . set_response_header ( CONTENT_TYPE , APPLICATION_JSON )
4+ ctx. set_response_header ( CONNECTION , CONNECTION_KEEP_ALIVE )
85 . await
96 . set_response_header ( SERVER , HYPERLANE )
107 . await
118 . set_response_header ( DATE , gmt ( ) )
129 . await ;
10+ #[ cfg( feature = "plaintext" ) ]
11+ {
12+ set_response_header ( CONTENT_TYPE , TEXT_PLAIN ) . await ;
13+ }
14+ #[ cfg( feature = "fortunes" ) ]
15+ {
16+ ctx = ctx
17+ . set_response_header ( CONTENT_TYPE , content_type_charset ( TEXT_HTML , UTF8 ) )
18+ . await ;
19+ }
20+ #[ cfg( any(
21+ feature = "json" ,
22+ feature = "db" ,
23+ feature = "query" ,
24+ feature = "update" ,
25+ feature = "cached_query"
26+ ) ) ]
27+ {
28+ ctx = ctx
29+ . set_response_header ( CONTENT_TYPE , APPLICATION_JSON )
30+ . await ;
31+ }
1332}
Original file line number Diff line number Diff line change @@ -10,11 +10,7 @@ pub async fn json(ctx: Context) {
1010}
1111
1212pub async fn plaintext ( ctx : Context ) {
13- let _ = ctx
14- . set_response_header ( CONTENT_TYPE , TEXT_PLAIN )
15- . await
16- . send_response ( 200 , RESPONSEDATA_BIN )
17- . await ;
13+ let _ = ctx. send_response ( 200 , RESPONSEDATA_BIN ) . await ;
1814}
1915
2016pub async fn db ( ctx : Context ) {
@@ -56,11 +52,7 @@ pub async fn fortunes(ctx: Context) {
5652 ) ) ;
5753 fortunes_list. sort_by ( |it, next| it. message . cmp ( & next. message ) ) ;
5854 let res: String = FortunesTemplate :: new ( fortunes_list) . to_string ( ) ;
59- let _ = ctx
60- . set_response_header ( CONTENT_TYPE , content_type_charset ( TEXT_HTML , UTF8 ) )
61- . await
62- . send_response ( 200 , res)
63- . await ;
55+ let _ = ctx. send_response ( 200 , res) . await ;
6456}
6557
6658pub async fn updates ( ctx : Context ) {
Original file line number Diff line number Diff line change @@ -24,17 +24,30 @@ async fn init_server() {
2424 server. http_line_buffer_size ( 256 ) . await ;
2525 server. websocket_buffer_size ( 256 ) . await ;
2626 server. request_middleware ( request) . await ;
27+ #[ cfg( feature = "plaintext" ) ]
2728 server. route ( "/plaintext" , plaintext) . await ;
29+ #[ cfg( feature = "json" ) ]
2830 server. route ( "/json" , json) . await ;
31+ #[ cfg( feature = "cached_query" ) ]
2932 server. route ( "/cached-quer" , cached_queries) . await ;
33+ #[ cfg( feature = "db" ) ]
3034 server. route ( "/db" , db) . await ;
35+ #[ cfg( feature = "query" ) ]
3136 server. route ( "/query" , queries) . await ;
37+ #[ cfg( feature = "fortunes" ) ]
3238 server. route ( "/fortunes" , fortunes) . await ;
39+ #[ cfg( feature = "update" ) ]
3340 server. route ( "/upda" , updates) . await ;
3441 server. listen ( ) . await . unwrap ( ) ;
3542}
3643
3744async fn init ( ) {
45+ #[ cfg( any(
46+ feature = "db" ,
47+ feature = "query" ,
48+ feature = "update" ,
49+ feature = "fortunes"
50+ ) ) ]
3851 init_db ( ) . await ;
3952 init_server ( ) . await ;
4053}
You can’t perform that action at this time.
0 commit comments