feat: first commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal 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
6
Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust-http-server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
28
src/main.rs
Normal file
28
src/main.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user