Fixed main - next step to make it properly iterate

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

@ -12,12 +12,6 @@ struct Asset;
fn main() {
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() {
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 page;
let mut status_line = "HTTP/1.1 404 NOT FOUND";
if request_line == "GET / HTTP/1.1" {
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 request_line == "GET /style.css HTTP/1.1" {
status_line = "HTTP/1.1 200 OK";
page = Asset::get("style.css").unwrap();
content = std::str::from_utf8(page.data.as_ref()).unwrap();
let end = request_line.len()-9;
let keyword = &request_line[0..3];
let path = &request_line[5..end];
let version = &request_line[(end+1)..request_line.len()];
println!("Line length: {}{}{}", keyword, path, version);
if keyword == "GET" {
if version == "HTTP/1.1" {
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 length = content.len();

Loading…
Cancel
Save