1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-12-01 02:44:37 +01:00

simplify handler path processing

This commit is contained in:
Nikolay Kim 2018-09-03 11:28:47 -07:00
parent b7a73e0a4f
commit 24d1228943
2 changed files with 3 additions and 13 deletions

View File

@ -447,11 +447,8 @@ where
{ {
let mut path = path.trim().trim_right_matches('/').to_owned(); let mut path = path.trim().trim_right_matches('/').to_owned();
if !path.is_empty() && !path.starts_with('/') { if !path.is_empty() && !path.starts_with('/') {
path.insert(0, '/') path.insert(0, '/');
} };
if path.len() > 1 && path.ends_with('/') {
path.pop();
}
self.parts self.parts
.as_mut() .as_mut()
.expect("Use after finish") .expect("Use after finish")

View File

@ -313,14 +313,7 @@ impl<S: 'static> Scope<S> {
/// } /// }
/// ``` /// ```
pub fn handler<H: Handler<S>>(mut self, path: &str, handler: H) -> Scope<S> { pub fn handler<H: Handler<S>>(mut self, path: &str, handler: H) -> Scope<S> {
let mut path = path.trim().trim_right_matches('/').to_owned(); let path = insert_slash(path.trim().trim_right_matches('/'));
if !path.is_empty() && !path.starts_with('/') {
path.insert(0, '/')
}
if path.len() > 1 && path.ends_with('/') {
path.pop();
}
Rc::get_mut(&mut self.router) Rc::get_mut(&mut self.router)
.expect("Multiple copies of scope router") .expect("Multiple copies of scope router")
.register_handler(&path, Box::new(WrapHandler::new(handler)), None); .register_handler(&path, Box::new(WrapHandler::new(handler)), None);