1use std::{thread, time::Duration};
2
3use connectionthreadpool::ThreadPool;
4use httpconstants::HttpConstants;
5use httpserver::HttpServer;
6
7pub mod connectionthreadpool;
8pub mod httpreader;
9pub mod httpconstants;
10pub mod httpserver;
11pub mod httperror;
12pub mod executor;
13
14fn main() {
15 println!("{:?}", HttpConstants::get_current_formatted_date());
16
17 let mut http_server : HttpServer<ThreadPool> = HttpServer::new(9000, 10000, ThreadPool::new(16));
18
19 http_server.add_endpoint("/", | mut reader | {
20 let mut vec_response : Vec<u8> = Vec::new();
21 vec_response.append(&mut "<h1>Hi from http</h1>this thing works".to_string().into_bytes());
22 reader.write_response_headers(200, vec_response.len()).unwrap_or_default();
23 reader.write_response_body(vec_response.as_slice()).unwrap_or_default();
24 });
25
26 http_server.add_endpoint("/sleep", | mut reader | {
27 thread::sleep(Duration::from_secs(5));
28 let mut vec_response : Vec<u8> = Vec::new();
29 vec_response.append(&mut "<h1>Hi from http</h1>i woke up from my sleep".to_string().into_bytes());
30 reader.write_response_headers(200, vec_response.len()).unwrap_or_default();
31 reader.write_response_body(vec_response.as_slice()).unwrap_or_default();
32 });
33
34 http_server.start().unwrap();
35
36}