From cbbea4738139a31fa9c95e15e2b9cba166111e15 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 29 May 2025 10:23:05 -0600 Subject: feat: return a homepage --- public/index.html | 10 ++++++++++ src/main.rs | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 public/index.html diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..0062a27 --- /dev/null +++ b/public/index.html @@ -0,0 +1,10 @@ + + + + + Hello, world! + + +

Hello, world!

+ + diff --git a/src/main.rs b/src/main.rs index 435aba8..01e2d66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +use std::fs; use std::io::BufReader; use std::io::prelude::*; use std::net::TcpListener; @@ -23,8 +24,12 @@ fn handle_connection(mut stream: TcpStream) { .collect(); println!("{http_request:#?}"); - let response = "HTTP/1.1 200 OK\r\n\r\n"; - println!("{response}"); + + let status_line = "HTTP/1.1 200 OK"; + let contents = fs::read_to_string("./public/index.html").unwrap(); + let length = contents.len(); + let response = format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"); + stream.write_all(response.as_bytes()).unwrap(); } -- cgit v1.2.3