diff --git a/src/ear.rs b/src/ear.rs index fb7bc5e..e8efd06 100644 --- a/src/ear.rs +++ b/src/ear.rs @@ -75,10 +75,16 @@ fn parse_uri(full_request: &str) -> Result { let method: String = full_request.split_whitespace().nth(0).unwrap().to_string(); let uri = full_request.split_whitespace().nth(1).unwrap(); let uri = decode(uri).expect("UTF-8").to_string(); + let uri = uri + .split("/") + .filter(|val| !val.is_empty()) + .collect::>(); - if let 3 = uri.chars().filter(|c| *c == '/').count() { - let section: String = uri.split("/").nth(2).unwrap().to_string(); - let requested_data = uri.split("/").nth(3).unwrap().to_string(); + if uri.len() != 3 || uri[0] != "api" { + Err(ReqParseError("Malformed URI".to_string())) + } else { + let section = uri[1].to_string(); + let requested_data = uri[2].to_string(); let request = Request { method, @@ -87,8 +93,6 @@ fn parse_uri(full_request: &str) -> Result { }; Ok(request) - } else { - Err(ReqParseError("Malformed URI".to_string())) } }