rust is getting sleepy... very sleep-zzzzz
This commit is contained in:
		
							parent
							
								
									8c1f52f39d
								
							
						
					
					
						commit
						f38b547408
					
				| @ -1,7 +1,9 @@ | ||||
| use std::io::prelude::*; | ||||
| use std::fs; | ||||
| use std::net::TcpStream; | ||||
| use std::net::TcpListener; | ||||
| use std::fs; | ||||
| use std::thread; | ||||
| use std::time::Duration; | ||||
| 
 | ||||
| fn main() { | ||||
|     let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); | ||||
| @ -21,9 +23,13 @@ fn handle_connection(mut stream: TcpStream) { | ||||
|     println!("Request: {}", String::from_utf8_lossy(&buffer[..])); | ||||
| 
 | ||||
|     let get = b"GET / HTTP/1.1\r\n"; | ||||
|     let sleep = b"GET /sleep HTTP/1.1\r\n"; | ||||
| 
 | ||||
|     let (headers, response) = if buffer.starts_with(get) { | ||||
|         ("HTTP/1.1 200 OK\r\n\r\n", "index.html") | ||||
|     } else if buffer.starts_with(sleep) { | ||||
|         thread::sleep(Duration::from_secs(5)); | ||||
|         ("HTTP/1.1 200 OK\r\n\r\n", "index.html") | ||||
|     } else { | ||||
|         ("HTTP/1.1 404 Not Found\r\n\r\n", "404.html") | ||||
|     }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user