Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions delayserver/src/main.rs
Original file line number Diff line number Diff line change
@@ -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}

Expand All @@ -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}")]
Expand All @@ -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
}