summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/index.html10
-rw-r--r--src/main.rs9
2 files changed, 17 insertions, 2 deletions
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 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Hello, world!</title>
+ </head>
+ <body>
+ <h1>Hello, world!</h1>
+ </body>
+</html>
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();
}