Skip to content

Commit

Permalink
rework ResourceMap internals (actix#2337)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay authored Sep 1, 2021
1 parent 7d01ece commit 373b3f9
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 200 deletions.
4 changes: 2 additions & 2 deletions src/app_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
.into_iter()
.for_each(|mut srv| srv.register(&mut config));

let mut rmap = ResourceMap::new(ResourceDef::new(""));
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));

let (config, services) = config.into_services();

Expand All @@ -104,7 +104,7 @@ where

// complete ResourceMap tree creation
let rmap = Rc::new(rmap);
rmap.finish(rmap.clone());
ResourceMap::finish(&rmap);

// construct all async data factory futures
let factory_futs = join_all(self.async_data_factories.iter().map(|f| f()));
Expand Down
9 changes: 4 additions & 5 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ mod tests {
let mut res = ResourceDef::new("/user/{name}.{ext}");
res.set_name("index");

let mut rmap = ResourceMap::new(ResourceDef::new(""));
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));
rmap.add(&mut res, None);
assert!(rmap.has_resource("/user/test.html"));
assert!(!rmap.has_resource("/test/unknown"));
Expand Down Expand Up @@ -541,7 +541,7 @@ mod tests {
let mut rdef = ResourceDef::new("/index.html");
rdef.set_name("index");

let mut rmap = ResourceMap::new(ResourceDef::new(""));
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));
rmap.add(&mut rdef, None);

assert!(rmap.has_resource("/index.html"));
Expand All @@ -562,7 +562,7 @@ mod tests {
let mut rdef = ResourceDef::new("/index.html");
rdef.set_name("index");

let mut rmap = ResourceMap::new(ResourceDef::new(""));
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));
rmap.add(&mut rdef, None);

assert!(rmap.has_resource("/index.html"));
Expand All @@ -581,9 +581,8 @@ mod tests {

rdef.set_name("youtube");

let mut rmap = ResourceMap::new(ResourceDef::new(""));
let mut rmap = ResourceMap::new(ResourceDef::prefix(""));
rmap.add(&mut rdef, None);
assert!(rmap.has_resource("https://youtube.com/watch/unknown"));

let req = TestRequest::default().rmap(rmap).to_http_request();
let url = req.url_for("youtube", &["oHg5SJYRHA0"]);
Expand Down
Loading

0 comments on commit 373b3f9

Please sign in to comment.