← 返回卡片

原书出处

The Rust Programming Language(第2版)

20 最终项目:构建多线程 Web 服务器 Validating the Request and Selectively Responding

第 2 版 · 核验版本的摘录快照 · 导入于 2026-11-24T14:01:16.975Z

--snip-- fn handle_connection(mut stream: TcpStream) { --snip-- let (status_line, filename) = if request_line == "GET / HTTP/1.1" { ("HTTP/1.1 200 OK", "hello.html") } else { ("HTTP/1.1 404 NOT FOUND", "404.html") }; let contents = fs::read_to_string(filename).unwrap(); let length = contents.len(); let response = format!( "{status_line}\r\n\ Content-Length: {length}\r\n\r\n\ {contents}" ); stream.write_all(response.as_bytes()).unwrap(); }

此预览只包含定位所需的摘录和上下文。

原书定位详情

来源:a19c7933-4eda-4176-aebd-30fe7e1ad292

正文位置:extracted/The Rust Programming Language(第2版)/_epub-src/c20.xhtml

EPUB SHA-256:610e9a4ca266a389faba5ffed033dc4bcae1c910c6259ea8ab73a6e93fbb9374