#7 reading from a file and building the response
This commit is contained in:
parent
1fc91880d8
commit
793daa9617
2 changed files with 16 additions and 2 deletions
9
src/hello.html
Normal file
9
src/hello.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Hello Rustacean!</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello Rustacean!</h1>
|
||||
</html>
|
||||
|
|
@ -15,7 +15,12 @@ fn handle_connection(mut stream: TcpStream) -> std::io::Result<()>{
|
|||
stream.read(&mut buffer)?;
|
||||
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
||||
|
||||
let response = "HTTP/1.1 200 OK\r\n\r\n";
|
||||
let contents = include_str!("hello.html");
|
||||
let response = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}",
|
||||
contents.len(),
|
||||
contents
|
||||
);
|
||||
stream.write(response.as_bytes())?;
|
||||
stream.flush()?;
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue