projects
/
learn-rust.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f95d7fa
)
simple-http: Introduce a slow path
author
Martin Pitt
<martin@piware.de>
Sun, 5 Sep 2021 06:09:28 +0000
(08:09 +0200)
committer
Martin Pitt
<martin@piware.de>
Sun, 5 Sep 2021 06:09:28 +0000
(08:09 +0200)
simple-http/src/main.rs
patch
|
blob
|
history
diff --git
a/simple-http/src/main.rs
b/simple-http/src/main.rs
index 3316864c12bc5095f0b68c021ae0ea469a21c9da..d2d0f8801302d343ebd36dd7a1875049feda4292 100644
(file)
--- 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::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];
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")
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")
};
} else {
("404 NOT FOUND", "404.html")
};