From 4ccd093f060dfe589c0ec86e9047e350f50550f1 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 5 Sep 2021 08:09:28 +0200 Subject: [PATCH 1/1] simple-http: Introduce a slow path --- simple-http/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/simple-http/src/main.rs b/simple-http/src/main.rs index 3316864..d2d0f88 100644 --- a/simple-http/src/main.rs +++ b/simple-http/src/main.rs @@ -2,8 +2,8 @@ use std::io::prelude::*; use std::net::TcpListener; use std::net::TcpStream; -use std::fs; -use std::str; +use std::time::Duration; +use std::{fs, str, thread}; fn handle_connection(mut stream: TcpStream) { let mut buffer = [0; 1024]; @@ -38,6 +38,9 @@ fn handle_connection(mut stream: TcpStream) { let (code, file) = if path == "/" || path == "/index.html" { ("200 OK", "index.html") + } else if path == "/slow" { + thread::sleep(Duration::from_secs(5)); + ("200 OK", "index.html") } else { ("404 NOT FOUND", "404.html") }; -- 2.39.2