creating structs, enums, figuring out networking rules
This commit is contained in:
parent
6836cbf72e
commit
07f8985f19
4 changed files with 72 additions and 2 deletions
24
src/main.rs
24
src/main.rs
|
|
@ -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
19
src/request.rs
Normal 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
17
src/response.rs
Normal 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
14
src/shared_enums.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
pub enum ContentType {
|
||||
Text(TextType),
|
||||
Aplication(ApplicationType),
|
||||
}
|
||||
|
||||
pub enum TextType {
|
||||
Html,
|
||||
Css,
|
||||
Javascript,
|
||||
}
|
||||
|
||||
pub enum ApplicationType {
|
||||
Json,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue