|
|
|
|
|
|
|
|
let mut buffer = [0; 512]; |
|
|
let mut buffer = [0; 512]; |
|
|
stream.read(&mut buffer).unwrap(); |
|
|
stream.read(&mut buffer).unwrap(); |
|
|
|
|
|
|
|
|
let get = "GET / HTTP/1.1\r\n"; |
|
|
|
|
|
|
|
|
let get = b"GET / HTTP/1.1\r\n"; |
|
|
|
|
|
|
|
|
if buffer.starts_with(get) { |
|
|
if buffer.starts_with(get) { |
|
|
// It's the request we want |
|
|
// It's the request we want |
|
|
|
|
|
let status_line = "HTTP/1.1 200 OK\r\n\r\n"; |
|
|
let contents = fs::read_to_string("hello.html").unwrap(); |
|
|
let contents = fs::read_to_string("hello.html").unwrap(); |
|
|
let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents); |
|
|
|
|
|
|
|
|
let response = format!("{}{}", status_line, contents); |
|
|
|
|
|
|
|
|
stream.write(response.as_bytes()).unwrap(); |
|
|
stream.write(response.as_bytes()).unwrap(); |
|
|
|
|
|
|
|
|
stream.flush().unwrap(); |
|
|
stream.flush().unwrap(); |
|
|
} else { |
|
|
} else { |
|
|
// a different request so who cares |
|
|
|
|
|
|
|
|
let status_line = "HTTP/1.1 404 NOT FOUND\r\n\r\n"; |
|
|
|
|
|
let contents = fs::read_to_string("404.html").unwrap(); |
|
|
|
|
|
let response = format!("{}{}", status_line, contents); |
|
|
|
|
|
|
|
|
|
|
|
stream.write(response.as_bytes()).unwrap(); |
|
|
|
|
|
stream.flush().unwrap(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|