Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
|
6ac5399822 |
17
src/main.rs
17
src/main.rs
|
@ -18,13 +18,22 @@ fn handle_connection(mut stream: TcpStream) {
|
|||
|
||||
stream.read(&mut buffer).unwrap();
|
||||
|
||||
let get = b"GET / HTTP/1.1\r\n";
|
||||
|
||||
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
||||
|
||||
let headers = "HTTP/1.1 200 OK\r\n\r\n".as_bytes();
|
||||
stream.write(headers).unwrap();
|
||||
let response = fs::read("public/index.html").unwrap();
|
||||
let response = &response[..];
|
||||
let (headers, response) = if buffer.starts_with(get) {
|
||||
|
||||
let bytes = fs::read("public/index.html").unwrap();
|
||||
("HTTP/1.1 200 OK\r\n\r\n".as_bytes(), bytes[..])
|
||||
|
||||
} else {
|
||||
|
||||
("HTTP/1.1 404 NOT FOUND\r\n\r\n".as_bytes(), "Couldn't find {}".as_bytes())
|
||||
|
||||
};
|
||||
|
||||
stream.write(headers).unwrap();
|
||||
stream.write(response).unwrap();
|
||||
stream.flush().unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue