fix some issues resolving the root url

Signed-off-by: Erik Hollensbe <linux@hollensbe.org>
This commit is contained in:
Erik Hollensbe
2022-01-23 17:54:28 -08:00
parent bca1d4444e
commit 728b96b5ba
2 changed files with 14 additions and 3 deletions
+2 -2
View File
@@ -147,9 +147,9 @@ impl<S: 'static + Clone + Send, T: TransientState + 'static + Clone + Send> App<
.status(sc)
.body(Body::default())
.unwrap()),
Error::InternalServerError(_) => Ok(Response::builder()
Error::InternalServerError(e) => Ok(Response::builder()
.status(StatusCode::INTERNAL_SERVER_ERROR)
.body(Body::default())
.body(Body::from(e.to_string()))
.unwrap()),
},
}
+12 -1
View File
@@ -64,11 +64,16 @@ impl Path {
}
pub(crate) fn extract(&self, provided: String) -> Result<Params, Error> {
if (provided == "" || provided == "/") && self.eq(&Self::default()) {
return Ok(Params::default());
}
let mut params = Params::default();
let parts: Vec<String> = provided
.split("/")
.map(|s| s.to_string())
.collect::<Vec<String>>();
let mut params = Params::default();
if parts.len() != self.0.len() {
return Err(Error::new("invalid parameters"));
@@ -168,6 +173,7 @@ mod tests {
#[test]
fn test_path() {
use super::Path;
use crate::Params;
use std::collections::BTreeMap;
let path = Path::new("/abc/def/ghi".to_string());
@@ -201,6 +207,11 @@ mod tests {
"/abc/:wooble/:wakka/jkl".to_string()
);
assert_eq!(
Path::new("/".to_string()).extract("/".to_string()).unwrap(),
Params::default()
);
assert_eq!(Path::default().to_string(), "/".to_string());
let path = Path::new("/".to_string());