1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-09-08 20:58:26 +00:00

simplify has_prefixed_route()

This commit is contained in:
Nikolay Kim 2018-07-16 11:10:51 +06:00
parent bce05e4fcb
commit b7a3fce17b

View file

@ -1,7 +1,6 @@
use std::cmp::min;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::path::Path;
use std::rc::Rc;
use regex::{escape, Regex};
@ -159,19 +158,11 @@ impl ResourceInfo {
/// It will not match against prefix in case it's not given. For example for `/name`
/// with a `/test` prefix would return `false`
pub fn has_prefixed_route(&self, path: &str) -> bool {
if self.prefix == 0 {
return self.has_route(path);
let prefix = self.prefix as usize;
if prefix >= path.len() {
return false;
}
let path_matcher = Path::new(if path.is_empty() { "/" } else { path });
let router_prefix = Path::new(&path[..(self.prefix as usize)]);
if let Ok(p) = path_matcher.strip_prefix(router_prefix) {
if let Some(p_str) = p.to_str() {
return self.has_route(&format!("/{}", p_str));
}
}
false
self.has_route(&path[prefix..])
}
}