From e81004a7ab047d646fb4e878847993c936e04f62 Mon Sep 17 00:00:00 2001 From: Zehua Zou <41586196+HuaHuaY@users.noreply.github.com> Date: Sun, 7 Feb 2021 00:15:34 +0800 Subject: [PATCH] Update ch20-01-single-threaded.md --- src/ch20-01-single-threaded.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ch20-01-single-threaded.md b/src/ch20-01-single-threaded.md index d5a2e9d..89b9daa 100644 --- a/src/ch20-01-single-threaded.md +++ b/src/ch20-01-single-threaded.md @@ -87,7 +87,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 512]; + let mut buffer = [0; 1024]; stream.read(&mut buffer).unwrap(); @@ -178,7 +178,7 @@ HTTP/1.1 200 OK\r\n\r\n # use std::io::prelude::*; # use std::net::TcpStream; fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 512]; + let mut buffer = [0; 1024]; stream.read(&mut buffer).unwrap(); @@ -230,12 +230,16 @@ use std::fs; // --snip-- fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 512]; + let mut buffer = [0; 1024]; stream.read(&mut buffer).unwrap(); let contents = fs::read_to_string("hello.html").unwrap(); - let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents); + let response = format!( + "HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}", + contents.len(), + contents + ); stream.write(response.as_bytes()).unwrap(); stream.flush().unwrap(); @@ -265,7 +269,7 @@ fn handle_connection(mut stream: TcpStream) { // --snip-- fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 512]; + let mut buffer = [0; 1024]; stream.read(&mut buffer).unwrap(); let get = b"GET / HTTP/1.1\r\n"; @@ -273,7 +277,11 @@ fn handle_connection(mut stream: TcpStream) { if buffer.starts_with(get) { let contents = fs::read_to_string("hello.html").unwrap(); - let response = format!("HTTP/1.1 200 OK\r\n\r\n{}", contents); + let response = format!( + "HTTP/1.1 200 OK\r\nContent-Length: {}\r\n\r\n{}", + contents.len(), + contents + ); stream.write(response.as_bytes()).unwrap(); stream.flush().unwrap();