feat: first commit

This commit is contained in:
2024-11-19 22:48:58 +01:00
commit b302923c86
4 changed files with 42 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@@ -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"

6
Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "rust-http-server"
version = "0.1.0"
edition = "2021"
[dependencies]

28
src/main.rs Normal file
View File

@@ -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);
}
}