From 9b39aa307b431f9de7732ac6bec2efe3c8ffb959 Mon Sep 17 00:00:00 2001 From: kalasutra <65849294+kalasutra@users.noreply.github.com> Date: Fri, 5 Nov 2021 23:58:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=B8=AD=E7=9A=84=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ch20-01-single-threaded.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ch20-01-single-threaded.md b/src/ch20-01-single-threaded.md index 8aeb64c..b88f22a 100644 --- a/src/ch20-01-single-threaded.md +++ b/src/ch20-01-single-threaded.md @@ -315,7 +315,11 @@ fn handle_connection(mut stream: TcpStream) { let status_line = "HTTP/1.1 404 NOT FOUND\r\n\r\n"; let contents = fs::read_to_string("404.html").unwrap(); - let response = format!("{}\r\nContent-Length: {}\r\n\r\n{}", status_line, contents); + let response = format!("{}\r\nContent-Length: {}\r\n\r\n{}", + status_line, + contents.len(), + contents + ); stream.write(response.as_bytes()).unwrap(); stream.flush().unwrap(); @@ -374,7 +378,11 @@ fn handle_connection(mut stream: TcpStream) { let contents = fs::read_to_string(filename).unwrap(); - let response = format!("{}\r\nContent-Length: {}\r\n\r\n{}", status_line, contents); + let response = format!("{}\r\nContent-Length: {}\r\n\r\n{}", + status_line, + contents.len(), + contents + ); stream.write(response.as_bytes()).unwrap(); stream.flush().unwrap();