From 582f8399777bb19e4e6ef30b93901610fa67751f Mon Sep 17 00:00:00 2001 From: Snorre Date: Fri, 4 Apr 2025 18:47:23 +0200 Subject: [PATCH] fucking webcrawler took down my site --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 162acaf..359f798 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,14 +31,14 @@ struct Request { path: Option, } impl Request { - pub fn from(string: &str) -> Self { + pub fn from(string: &str) -> Option { let mut parts = string.split(" "); - Self { + Some(Self { method: match parts.next().expect("Invalid request") { "GET" => RequestMethod::GET, "POST" => RequestMethod::POST, - _ => panic!("Unknown method"), // TODO: fix PUT crashing entire website + _ => None? }, path: Some( parts @@ -49,7 +49,7 @@ impl Request { .unwrap() .to_string(), ), - } + }) } pub fn file(&self) -> Option { if self.path == None { @@ -115,6 +115,12 @@ fn handle_connection(mut stream: TcpStream) { let req = Request::from(http_request.get(0).expect("Empty request")); + if req.is_none() { + return; + }; + + let req = req.unwrap(); + if req.path == Some("/posts/index".to_string()) { stream .write_all(