|
|
@ -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,15 +25,24 @@ 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; |
|
|
|
|
|
|
|
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"; |
|
|
|
status_line = "HTTP/1.1 200 OK"; |
|
|
|
page = Asset::get("index.html").unwrap(); |
|
|
|
page = Asset::get("index.html").unwrap(); |
|
|
|
content = std::str::from_utf8(page.data.as_ref()).unwrap(); |
|
|
|
content = std::str::from_utf8(page.data.as_ref()).unwrap(); |
|
|
|
}else if request_line == "GET /style.css HTTP/1.1" { |
|
|
|
}else if path == "style.css" { |
|
|
|
status_line = "HTTP/1.1 200 OK"; |
|
|
|
status_line = "HTTP/1.1 200 OK"; |
|
|
|
page = Asset::get("style.css").unwrap(); |
|
|
|
page = Asset::get("style.css").unwrap(); |
|
|
|
content = std::str::from_utf8(page.data.as_ref()).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(); |
|
|
|
let response = format!( |
|
|
|
let response = format!( |
|
|
|