keep alive working I feel like a god frfr (it's late an this is my personal project so if anyone is reading this (including my future self) why?)
This commit is contained in:
parent
40ccfa01d6
commit
a9ccdaf3f5
3 changed files with 20 additions and 7 deletions
|
|
@ -9,7 +9,7 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
request::ServerPath,
|
||||
request::Connection,
|
||||
response::{Response, ResponseCode, ResponseHeader},
|
||||
shared_enums::{Content, ContentType},
|
||||
};
|
||||
|
|
@ -30,12 +30,12 @@ fn main() -> std::io::Result<()> {
|
|||
println!("{req:?}");
|
||||
|
||||
let response = match req.path.path.to_string().as_str(){
|
||||
"css.css" => Response::new().with_code(ResponseCode::Ok).with_data(b"body{background-color: #000000;}".to_vec()).with_header(ResponseHeader::ContentType(Content::new(ContentType::Text(shared_enums::TextType::Css)))),
|
||||
"css.css" => Response::new().with_code(ResponseCode::Ok).with_data(b"body{background-color: #ff0000;}".to_vec()).with_header(ResponseHeader::ContentType(Content::new(ContentType::Text(shared_enums::TextType::Css)))),
|
||||
|
||||
_ => Response::new()
|
||||
.with_code(ResponseCode::Ok)
|
||||
.with_data(b"<!doctype html><html lang=\"en\"><head><link rel=\"stylesheet\" href=\"css.css\"><meta charset=\"UTF-8\"/><title>Hello World!</title></head><body><h1>Ahojky</h1><p>Jou jou jou</p></body></html>".to_vec())
|
||||
.with_header(ResponseHeader::ContentType(Content::html_utf8())),
|
||||
.with_header(ResponseHeader::ContentType(Content::html_utf8())).with_header(ResponseHeader::Connection(Connection::KeepAlive)),
|
||||
};
|
||||
|
||||
response.respond(&mut stream)?;
|
||||
|
|
@ -45,6 +45,7 @@ fn main() -> std::io::Result<()> {
|
|||
if req.headers.contains(&request::RequestHeader::Connection(
|
||||
request::Connection::Close,
|
||||
)) {
|
||||
println!("Connection closed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue