Browse Source

Add hello page

master
Noelle 4 years ago
parent
commit
4b8b243310
2 changed files with 13 additions and 1 deletions
  1. 11
    0
      hello.html
  2. 2
    1
      src/main.rs

+ 11
- 0
hello.html View File

@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello!</title>
</head>
<body>
<h1>Hello!</h1>
<p>Hi from Rust</p>
</body>
</html>

+ 2
- 1
src/main.rs View File

@@ -17,7 +17,8 @@ fn handle_connecton(mut stream: TcpStream) {

stream.read(&mut buffer).unwrap();

let response = "HTTP/1.1 200 OK\r\n\r\n";
let contents = fs::read_to_string("hello.html").unwrap();
let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents);
stream.write(response.as_bytes()).unwrap();

stream.flush().unwrap();

Loading…
Cancel
Save