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+ } ;
37
48const EXPLANATION : & str =
59"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]
812
913If 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'.
1115
12- On reception , it immieiately reports the following to the console:
16+ Upon receiving a request , it immediately reports the following to the console:
1317
1418{Message #} - {delay in ms}: {message}
1519
@@ -18,6 +22,7 @@ The server then delays the response for the requested time and echoes the messag
1822REQUESTS:
1923--------
2024" ;
25+
2126static COUNTER : AtomicUsize = AtomicUsize :: new ( 1 ) ;
2227
2328#[ get( "/{delay}/{message}" ) ]
@@ -34,13 +39,10 @@ async fn main() -> std::io::Result<()> {
3439 let url = env:: args ( )
3540 . nth ( 1 )
3641 . unwrap_or_else ( || String :: from ( "localhost" ) ) ;
37-
42+
3843 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
4648}
0 commit comments