Finish parsing the API uri
This commit is contained in:
parent
4b85869505
commit
b33cdc6a78
1 changed files with 9 additions and 5 deletions
14
src/ear.rs
14
src/ear.rs
|
@ -75,10 +75,16 @@ fn parse_uri(full_request: &str) -> Result<Request, ReqParseError> {
|
|||
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::<Vec<&str>>();
|
||||
|
||||
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<Request, ReqParseError> {
|
|||
};
|
||||
|
||||
Ok(request)
|
||||
} else {
|
||||
Err(ReqParseError("Malformed URI".to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue