示例代码缺失

示例20-9,20-7缺少Content-Length
pull/545/head
sai0556 3 years ago committed by GitHub
parent b7aeabd042
commit de9b29ad1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -315,7 +315,7 @@ fn handle_connection(mut stream: TcpStream) {
let status_line = "HTTP/1.1 404 NOT FOUND\r\n\r\n"; let status_line = "HTTP/1.1 404 NOT FOUND\r\n\r\n";
let contents = fs::read_to_string("404.html").unwrap(); let contents = fs::read_to_string("404.html").unwrap();
let response = format!("{}{}", status_line, contents); let response = format!("{}\r\nContent-Length: {}\r\n\r\n{}", status_line, contents);
stream.write(response.as_bytes()).unwrap(); stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap(); stream.flush().unwrap();
@ -374,7 +374,7 @@ fn handle_connection(mut stream: TcpStream) {
let contents = fs::read_to_string(filename).unwrap(); let contents = fs::read_to_string(filename).unwrap();
let response = format!("{}{}", status_line, contents); let response = format!("{}\r\nContent-Length: {}\r\n\r\n{}", status_line, contents);
stream.write(response.as_bytes()).unwrap(); stream.write(response.as_bytes()).unwrap();
stream.flush().unwrap(); stream.flush().unwrap();

Loading…
Cancel
Save