Fixed main - next step to make it properly iterate

main
silverwizard 2 years ago
parent 9ca4fa5b8a
commit bf35ed4680
  1. 31
      src/main.rs

@ -12,12 +12,6 @@ struct Asset;
fn main() { fn main() {
let listener = TcpListener::bind("0.0.0.0:7878").unwrap(); let listener = TcpListener::bind("0.0.0.0:7878").unwrap();
for file in Asset::iter() {
let page = Asset::get(&file.to_string()).unwrap();
println!("{:?}", std::str::from_utf8(page.data.as_ref()));
}
for stream in listener.incoming() { for stream in listener.incoming() {
let stream = stream.unwrap(); let stream = stream.unwrap();
@ -31,14 +25,23 @@ fn handle_connection(mut stream: TcpStream) {
let mut content = "<html><head><strong>Error 404</strong><br /></head><body><img src=\"https://http.cat/404\"></img><br /><p>Not Found</p></body></html>"; let mut content = "<html><head><strong>Error 404</strong><br /></head><body><img src=\"https://http.cat/404\"></img><br /><p>Not Found</p></body></html>";
let mut page; let mut page;
let mut status_line = "HTTP/1.1 404 NOT FOUND"; let mut status_line = "HTTP/1.1 404 NOT FOUND";
if request_line == "GET / HTTP/1.1" { let end = request_line.len()-9;
status_line = "HTTP/1.1 200 OK"; let keyword = &request_line[0..3];
page = Asset::get("index.html").unwrap(); let path = &request_line[5..end];
content = std::str::from_utf8(page.data.as_ref()).unwrap(); let version = &request_line[(end+1)..request_line.len()];
}else if request_line == "GET /style.css HTTP/1.1" { println!("Line length: {}{}{}", keyword, path, version);
status_line = "HTTP/1.1 200 OK"; if keyword == "GET" {
page = Asset::get("style.css").unwrap(); if version == "HTTP/1.1" {
content = std::str::from_utf8(page.data.as_ref()).unwrap(); if path == "index.html" || path == "" {
status_line = "HTTP/1.1 200 OK";
page = Asset::get("index.html").unwrap();
content = std::str::from_utf8(page.data.as_ref()).unwrap();
}else if path == "style.css" {
status_line = "HTTP/1.1 200 OK";
page = Asset::get("style.css").unwrap();
content = std::str::from_utf8(page.data.as_ref()).unwrap();
}
}
} }
let status_line = "HTTP/1.1 200 OK"; let status_line = "HTTP/1.1 200 OK";
let length = content.len(); let length = content.len();

Loading…
Cancel
Save