diff --git a/delayserver/src/main.rs b/delayserver/src/main.rs index 1c1189d..a6d35a7 100644 --- a/delayserver/src/main.rs +++ b/delayserver/src/main.rs @@ -1,15 +1,19 @@ -use std::{time::Duration, sync::atomic::{AtomicUsize, Ordering}, env}; -use actix_web::{Responder, get, HttpServer, App, web, rt::time::sleep}; +use actix_web::{get, rt::time::sleep, web, App, HttpServer, Responder}; +use std::{ + env, + sync::atomic::{AtomicUsize, Ordering}, + time::Duration, +}; const EXPLANATION: &str = "USAGE: -Delay server works by issuing a http GET request in the format: -http://localhost:8080/[delay in ms]/[UrlEncoded message] +Delay server works by issuing an HTTP GET request in the format: +http://localhost:8080/[delay in ms]/[URL-encoded message] If an argument is passed in when delayserver is started, that -argument will be used as the url instead of 'localhost' +argument will be used as the URL instead of 'localhost'. -On reception, it immieiately reports the following to the console: +Upon receiving a request, it immediately reports the following to the console: {Message #} - {delay in ms}: {message} @@ -18,6 +22,7 @@ The server then delays the response for the requested time and echoes the messag REQUESTS: -------- "; + static COUNTER: AtomicUsize = AtomicUsize::new(1); #[get("/{delay}/{message}")] @@ -34,13 +39,10 @@ async fn main() -> std::io::Result<()> { let url = env::args() .nth(1) .unwrap_or_else(|| String::from("localhost")); - + println!("{EXPLANATION}"); - HttpServer::new(|| { - App::new() - .service(delay) - }) - .bind((url, 8080))? - .run() - .await + HttpServer::new(|| App::new().service(delay)) + .bind((url, 8080))? + .run() + .await }