creating structs, enums, figuring out networking rules

This commit is contained in:
maxstrb 2025-10-04 23:03:19 +02:00
parent 6836cbf72e
commit 07f8985f19
4 changed files with 72 additions and 2 deletions

View file

@ -1,3 +1,23 @@
fn main() {
println!("Hello, world!");
mod request;
mod response;
mod shared_enums;
use std::{
io::{BufRead, BufReader, Write},
net::TcpListener,
};
fn main() -> std::io::Result<()> {
let listener = TcpListener::bind("127.0.0.1:8080")?;
for incoming_stream in listener.incoming() {
let stream = incoming_stream?;
let mut reader = BufReader::new(&stream);
let mut line = Vec::<u8>::new();
let mut writer = stream;
writer.write_all("Ok".as_bytes())?;
writer.flush()?;
}
Ok(())
}

19
src/request.rs Normal file
View file

@ -0,0 +1,19 @@
use crate::shared_enums::ContentType;
pub struct Request {
first_line: String,
headers: Vec<RequestHeader>,
data: Vec<u8>,
}
pub enum RequestHeader {
Host(String),
UserAgent(String),
ContentType(ContentType),
Accept((String, String)),
Other(String, String),
}
impl Request {
fn from_bufreader
}

17
src/response.rs Normal file
View file

@ -0,0 +1,17 @@
use crate::shared_enums::ContentType;
pub struct Response {
first_line: String,
headers: Vec<ResponseHeader>,
data: Vec<u8>,
}
pub enum ResponseHeader {
ContentLength(u32),
ContentType(ContentType),
CacheControl(CacheControl),
}
pub enum CacheControl {
NoStore,
}

14
src/shared_enums.rs Normal file
View file

@ -0,0 +1,14 @@
pub enum ContentType {
Text(TextType),
Aplication(ApplicationType),
}
pub enum TextType {
Html,
Css,
Javascript,
}
pub enum ApplicationType {
Json,
}