WIP if-else refs
This commit is contained in:
parent
9bef4073a8
commit
6ac5399822
17
src/main.rs
17
src/main.rs
|
@ -18,13 +18,22 @@ fn handle_connection(mut stream: TcpStream) {
|
||||||
|
|
||||||
stream.read(&mut buffer).unwrap();
|
stream.read(&mut buffer).unwrap();
|
||||||
|
|
||||||
|
let get = b"GET / HTTP/1.1\r\n";
|
||||||
|
|
||||||
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
||||||
|
|
||||||
let headers = "HTTP/1.1 200 OK\r\n\r\n".as_bytes();
|
let (headers, response) = if buffer.starts_with(get) {
|
||||||
stream.write(headers).unwrap();
|
|
||||||
let response = fs::read("public/index.html").unwrap();
|
|
||||||
let response = &response[..];
|
|
||||||
|
|
||||||
|
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.write(response).unwrap();
|
||||||
stream.flush().unwrap();
|
stream.flush().unwrap();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue