Don't unwrap in parse_uri anymore
This commit is contained in:
parent
56881725aa
commit
d02a4a9350
1 changed files with 5 additions and 4 deletions
|
@ -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<Request, ReqParseError> {
|
||||
let method = match full_request.split_whitespace().nth(0) {
|
||||
Some("GET") => HttpMethod::Get,
|
||||
|
@ -96,8 +95,10 @@ fn parse_uri(full_request: &str) -> Result<Request, ReqParseError> {
|
|||
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())
|
||||
|
|
Loading…
Reference in a new issue