Skip to content

Commit

Permalink
Merge pull request #347 from ifconfig/master
Browse files Browse the repository at this point in the history
Codeblock 20-2
  • Loading branch information
damoasda authored Sep 29, 2023
2 parents 6d0d0c2 + d1b475e commit 3529d17
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/ch20-01-single-threaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ dass er wie Codeblock 20-2 aussieht.
<span class="filename">Dateiname: src/main.rs</span>

```rust,no_run
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
use std::{
io::{prelude::*, BufReader},
net::{TcpListener, TcpStream},
};
fn main() {
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
Expand All @@ -170,11 +171,14 @@ fn main() {
}
fn handle_connection(mut stream: TcpStream) {
let mut buffer = [0; 1024];
stream.read(&mut buffer).unwrap();
let buf_reader = BufReader::new(&mut stream);
let http_request: Vec<_> = buf_reader
.lines()
.map(|result| result.unwrap())
.take_while(|line| !line.is_empty())
.collect();
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
println!("Request: {:#?}", http_request);
}
```

Expand Down

0 comments on commit 3529d17

Please sign in to comment.