mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
592 B
26 lines
592 B
use std::{
|
|
io::{prelude::*, BufReader},
|
|
net::{TcpListener, TcpStream},
|
|
};
|
|
|
|
fn main() {
|
|
let listener = TcpListener::bind("127.0.0.1:7878").unwrap();
|
|
|
|
for stream in listener.incoming() {
|
|
let stream = stream.unwrap();
|
|
|
|
handle_connection(stream);
|
|
}
|
|
}
|
|
|
|
fn handle_connection(mut stream: TcpStream) {
|
|
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: {:#?}", http_request);
|
|
}
|