Sfoglia il codice sorgente

Add hello page

master
Noelle 4 anni fa
parent
commit
4b8b243310
2 ha cambiato i file con 13 aggiunte e 1 eliminazioni
  1. 11
    0
      hello.html
  2. 2
    1
      src/main.rs

+ 11
- 0
hello.html Vedi 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 Vedi 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…
Annulla
Salva