fucking webcrawler took down my site
All checks were successful
Restart Website Service / restart_service (push) Successful in 1m4s

This commit is contained in:
Snorre 2025-04-04 18:47:23 +02:00
parent 55e61bf421
commit 582f839977

View file

@ -31,14 +31,14 @@ struct Request {
path: Option<String>,
}
impl Request {
pub fn from(string: &str) -> Self {
pub fn from(string: &str) -> Option<Self> {
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<PathBuf> {
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(