From 728b96b5baf42404df2ecebd90486bb127bec5d3 Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Sun, 23 Jan 2022 17:54:28 -0800 Subject: [PATCH] fix some issues resolving the root url Signed-off-by: Erik Hollensbe --- src/app.rs | 4 ++-- src/path.rs | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/app.rs b/src/app.rs index 41705ae..dfb11df 100644 --- a/src/app.rs +++ b/src/app.rs @@ -147,9 +147,9 @@ impl 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()), }, } diff --git a/src/path.rs b/src/path.rs index baca788..d22110d 100644 --- a/src/path.rs +++ b/src/path.rs @@ -64,11 +64,16 @@ impl Path { } pub(crate) fn extract(&self, provided: String) -> Result { + if (provided == "" || provided == "/") && self.eq(&Self::default()) { + return Ok(Params::default()); + } + + let mut params = Params::default(); + let parts: Vec = provided .split("/") .map(|s| s.to_string()) .collect::>(); - 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());