better path

This commit is contained in:
maxstrb 2025-10-18 20:42:33 +02:00
parent a9ccdaf3f5
commit 772cb421cb
4 changed files with 39 additions and 43 deletions

View file

@ -29,12 +29,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: #ff0000;}".to_vec()).with_header(ResponseHeader::ContentType(Content::new(ContentType::Text(shared_enums::TextType::Css)))),
let response = match req.path.to_matchable().as_slice(){
["css.css"] => Response::new().with_code(ResponseCode::Ok).with_data(b"body{background-color: #121212;} h1{color: #ffffff;} p{color: #025da9;}".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_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>HTTP server testing</h1><p>Lorem ipsum</p></body></html>".to_vec())
.with_header(ResponseHeader::ContentType(Content::html_utf8())).with_header(ResponseHeader::Connection(Connection::KeepAlive)),
};