From 9bef4073a86364db7a1c1d9355f884c80cb932cb Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 1 Oct 2018 19:12:19 -0600 Subject: [PATCH] read file as bytes (much advance so skip step) --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index fb1e232..c96f99c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,11 @@ fn handle_connection(mut stream: TcpStream) { println!("Request: {}", String::from_utf8_lossy(&buffer[..])); - let response = "HTTP/1.1 200 OK\r\n\r\n"; + 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[..]; - stream.write(response.as_bytes()).unwrap(); + stream.write(response).unwrap(); stream.flush().unwrap(); }