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:
parent
b7a73e0a4f
commit
24d1228943
@ -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")
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user