@@ -7,7 +7,7 @@ use ntex::http::header::{CONTENT_TYPE, SERVER};
7
7
use ntex:: http:: { HttpService , KeepAlive , Request , Response , StatusCode } ;
8
8
use ntex:: service:: { Service , ServiceCtx , ServiceFactory } ;
9
9
use ntex:: web:: { Error , HttpResponse } ;
10
- use ntex:: { time:: Seconds , util:: BoxFuture , util :: PoolId } ;
10
+ use ntex:: { time:: Seconds , util:: PoolId } ;
11
11
12
12
mod db;
13
13
mod utils;
@@ -17,52 +17,49 @@ struct App(db::PgConnection);
17
17
impl Service < Request > for App {
18
18
type Response = Response ;
19
19
type Error = Error ;
20
- type Future < ' f > = BoxFuture < ' f , Result < Response , Error > > where Self : ' f ;
21
20
22
- fn call < ' a > ( & ' a self , req : Request , _: ServiceCtx < ' a , Self > ) -> Self :: Future < ' a > {
23
- Box :: pin ( async move {
24
- match req. path ( ) {
25
- "/db" => {
26
- let body = self . 0 . get_world ( ) . await ;
27
- let mut res = HttpResponse :: with_body ( StatusCode :: OK , body. into ( ) ) ;
28
- res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
29
- res. headers_mut ( )
30
- . insert ( CONTENT_TYPE , utils:: HDR_JSON_CONTENT_TYPE ) ;
31
- Ok ( res)
32
- }
33
- "/fortunes" => {
34
- let body = self . 0 . tell_fortune ( ) . await ;
35
- let mut res = HttpResponse :: with_body ( StatusCode :: OK , body. into ( ) ) ;
36
- res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
37
- res. headers_mut ( )
38
- . insert ( CONTENT_TYPE , utils:: HDR_HTML_CONTENT_TYPE ) ;
39
- Ok ( res)
40
- }
41
- "/query" => {
42
- let worlds = self
43
- . 0
44
- . get_worlds ( utils:: get_query_param ( req. uri ( ) . query ( ) ) )
45
- . await ;
46
- let mut res = HttpResponse :: with_body ( StatusCode :: OK , worlds. into ( ) ) ;
47
- res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
48
- res. headers_mut ( )
49
- . insert ( CONTENT_TYPE , utils:: HDR_JSON_CONTENT_TYPE ) ;
50
- Ok ( res)
51
- }
52
- "/update" => {
53
- let worlds = self
54
- . 0
55
- . update ( utils:: get_query_param ( req. uri ( ) . query ( ) ) )
56
- . await ;
57
- let mut res = HttpResponse :: with_body ( StatusCode :: OK , worlds. into ( ) ) ;
58
- res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
59
- res. headers_mut ( )
60
- . insert ( CONTENT_TYPE , utils:: HDR_JSON_CONTENT_TYPE ) ;
61
- Ok ( res)
62
- }
63
- _ => Ok ( Response :: new ( StatusCode :: NOT_FOUND ) ) ,
21
+ async fn call ( & self , req : Request , _: ServiceCtx < ' _ , Self > ) -> Result < Response , Error > {
22
+ match req. path ( ) {
23
+ "/db" => {
24
+ let body = self . 0 . get_world ( ) . await ;
25
+ let mut res = HttpResponse :: with_body ( StatusCode :: OK , body. into ( ) ) ;
26
+ res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
27
+ res. headers_mut ( )
28
+ . insert ( CONTENT_TYPE , utils:: HDR_JSON_CONTENT_TYPE ) ;
29
+ Ok ( res)
64
30
}
65
- } )
31
+ "/fortunes" => {
32
+ let body = self . 0 . tell_fortune ( ) . await ;
33
+ let mut res = HttpResponse :: with_body ( StatusCode :: OK , body. into ( ) ) ;
34
+ res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
35
+ res. headers_mut ( )
36
+ . insert ( CONTENT_TYPE , utils:: HDR_HTML_CONTENT_TYPE ) ;
37
+ Ok ( res)
38
+ }
39
+ "/query" => {
40
+ let worlds = self
41
+ . 0
42
+ . get_worlds ( utils:: get_query_param ( req. uri ( ) . query ( ) ) )
43
+ . await ;
44
+ let mut res = HttpResponse :: with_body ( StatusCode :: OK , worlds. into ( ) ) ;
45
+ res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
46
+ res. headers_mut ( )
47
+ . insert ( CONTENT_TYPE , utils:: HDR_JSON_CONTENT_TYPE ) ;
48
+ Ok ( res)
49
+ }
50
+ "/update" => {
51
+ let worlds = self
52
+ . 0
53
+ . update ( utils:: get_query_param ( req. uri ( ) . query ( ) ) )
54
+ . await ;
55
+ let mut res = HttpResponse :: with_body ( StatusCode :: OK , worlds. into ( ) ) ;
56
+ res. headers_mut ( ) . insert ( SERVER , utils:: HDR_SERVER ) ;
57
+ res. headers_mut ( )
58
+ . insert ( CONTENT_TYPE , utils:: HDR_JSON_CONTENT_TYPE ) ;
59
+ Ok ( res)
60
+ }
61
+ _ => Ok ( Response :: new ( StatusCode :: NOT_FOUND ) ) ,
62
+ }
66
63
}
67
64
}
68
65
@@ -73,13 +70,12 @@ impl ServiceFactory<Request> for AppFactory {
73
70
type Error = Error ;
74
71
type Service = App ;
75
72
type InitError = ( ) ;
76
- type Future < ' f > = BoxFuture < ' f , Result < Self :: Service , Self :: InitError > > ;
77
73
78
- fn create ( & self , _: ( ) ) -> Self :: Future < ' _ > {
74
+ async fn create ( & self , _: ( ) ) -> Result < Self :: Service , Self :: InitError > {
79
75
const DB_URL : & str =
80
76
"postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world" ;
81
77
82
- Box :: pin ( async move { Ok ( App ( db:: PgConnection :: connect ( DB_URL ) . await ) ) } )
78
+ Ok ( App ( db:: PgConnection :: connect ( DB_URL ) . await ) )
83
79
}
84
80
}
85
81
@@ -97,6 +93,8 @@ async fn main() -> std::io::Result<()> {
97
93
HttpService :: build ( )
98
94
. keep_alive ( KeepAlive :: Os )
99
95
. client_timeout ( Seconds ( 0 ) )
96
+ . headers_read_rate ( Seconds :: ZERO , Seconds :: ZERO , 0 )
97
+ . payload_read_rate ( Seconds :: ZERO , Seconds :: ZERO , 0 )
100
98
. h1 ( AppFactory )
101
99
} ) ?
102
100
. workers ( num_cpus:: get ( ) )
0 commit comments