From d02a4a935055f046eae41f16a0c1b289fee7e3e9 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Sun, 8 Jan 2023 23:08:29 +0100 Subject: [PATCH] Don't unwrap in parse_uri anymore --- src/ear.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ear.rs b/src/ear.rs index 6f259e9..796da10 100644 --- a/src/ear.rs +++ b/src/ear.rs @@ -86,8 +86,7 @@ impl Ear { } } -/// Receives and parses a request from `receive_request` to dermine the function to call. -/// We are expecting the request to be like 'GET /api/titre/jean' +/// Receives and parses a request to dermine the function to call. fn parse_uri(full_request: &str) -> Result { let method = match full_request.split_whitespace().nth(0) { Some("GET") => HttpMethod::Get, @@ -96,8 +95,10 @@ fn parse_uri(full_request: &str) -> Result { None => return Err(ReqParseError("Malformed URI".to_string())), }; - let uri = full_request.split_whitespace().nth(1).unwrap(); - let uri = decode(uri).expect("UTF-8").to_string(); + let uri = match full_request.split_whitespace().nth(1) { + Some(uri) => decode(uri).expect("UTF-8").to_string(), + None => return Err(ReqParseError("Malformed URI".to_string())), + }; let uri = uri .split("/") .filter(|val| !val.is_empty())