1
- use std:: { time:: Duration , sync:: atomic:: { AtomicUsize , Ordering } , env} ;
2
- use actix_web:: { Responder , get, HttpServer , App , web, rt:: time:: sleep} ;
1
+ use actix_web:: { get, rt:: time:: sleep, web, App , HttpServer , Responder } ;
2
+ use std:: {
3
+ env,
4
+ sync:: atomic:: { AtomicUsize , Ordering } ,
5
+ time:: Duration ,
6
+ } ;
3
7
4
8
const EXPLANATION : & str =
5
9
"USAGE:
6
- Delay server works by issuing a http GET request in the format:
7
- http://localhost:8080/[delay in ms]/[UrlEncoded message]
10
+ Delay server works by issuing an HTTP GET request in the format:
11
+ http://localhost:8080/[delay in ms]/[URL-encoded message]
8
12
9
13
If an argument is passed in when delayserver is started, that
10
- argument will be used as the url instead of 'localhost'
14
+ argument will be used as the URL instead of 'localhost'.
11
15
12
- On reception , it immieiately reports the following to the console:
16
+ Upon receiving a request , it immediately reports the following to the console:
13
17
14
18
{Message #} - {delay in ms}: {message}
15
19
@@ -18,6 +22,7 @@ The server then delays the response for the requested time and echoes the messag
18
22
REQUESTS:
19
23
--------
20
24
" ;
25
+
21
26
static COUNTER : AtomicUsize = AtomicUsize :: new ( 1 ) ;
22
27
23
28
#[ get( "/{delay}/{message}" ) ]
@@ -34,13 +39,10 @@ async fn main() -> std::io::Result<()> {
34
39
let url = env:: args ( )
35
40
. nth ( 1 )
36
41
. unwrap_or_else ( || String :: from ( "localhost" ) ) ;
37
-
42
+
38
43
println ! ( "{EXPLANATION}" ) ;
39
- HttpServer :: new ( || {
40
- App :: new ( )
41
- . service ( delay)
42
- } )
43
- . bind ( ( url, 8080 ) ) ?
44
- . run ( )
45
- . await
44
+ HttpServer :: new ( || App :: new ( ) . service ( delay) )
45
+ . bind ( ( url, 8080 ) ) ?
46
+ . run ( )
47
+ . await
46
48
}
0 commit comments