Refactored project

This commit is contained in:
2021-05-15 21:20:02 +02:00
parent 4ce3569458
commit 19004d8cf1
5 changed files with 585 additions and 390 deletions

24
src/http/handler.rs Normal file
View File

@ -0,0 +1,24 @@
pub fn connection_handler(client: super::Stream) {
let mut client = super::HttpStream {
stream: client,
request_num: 0,
};
while client.request_num < super::REQUESTS_PER_CONNECTION {
request_handler(&mut client);
client.request_num += 1;
}
}
fn request_handler(client: &mut super::HttpStream) {
let req = super::parser::parse_request(&mut client.stream).unwrap();
println!("{} {}", req.method, req.uri);
let mut res = super::Response::new();
let doc = "<!DOCTYPE html><html><head><title>Locutus Server</title></head><body><h1>Hello World! :D</h1></body></html>";
res.add_header("Content-Length", doc.len().to_string().as_str());
res.add_header("Content-Type", "text/html; charset=utf-8");
res.send(&mut client.stream).unwrap();
client.stream.write_all(doc.as_bytes()).unwrap();
}