Skip to content

Commit

Permalink
reading the http request
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanushrajgp committed Jul 12, 2024
1 parent 85544f7 commit fcd7d21
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use std::net::TcpListener;
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();
println!("Connection Established!")
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);
}

0 comments on commit fcd7d21

Please sign in to comment.