feat: first commit
This commit is contained in:
commit
b302923c86
4 files changed
+42
No files matched your search
@@ -0,0 +1 @@
|
||||
/target
|
||||
Generated
+7
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust-http-server"
|
||||
version = "0.1.0"
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust-http-server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
use std::io::prelude::*;
|
||||
use std::net::{SocketAddr, TcpListener, TcpStream};
|
||||
|
||||
fn handle_petition(mut stream: TcpStream) -> std::io::Result<()> {
|
||||
let mut buffer = [0; 1024];
|
||||
|
||||
let amount = stream.read(&mut buffer)?;
|
||||
|
||||
println!(
|
||||
"Request: {} of {amount} bytes",
|
||||
String::from_utf8_lossy(&buffer[..])
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 80));
|
||||
|
||||
let listener = TcpListener::bind(addr).unwrap();
|
||||
|
||||
println!("Server up and running!");
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let _stream = stream.unwrap();
|
||||
println!("Connection established!");
|
||||
let _result = handle_petition(_stream);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user