diff --git a/src/request.rs b/src/request.rs index c36e87260..cc2edbe63 100644 --- a/src/request.rs +++ b/src/request.rs @@ -4,7 +4,7 @@ use std::{fmt, net}; use actix_http::http::{HeaderMap, Method, Uri, Version}; use actix_http::{Error, Extensions, HttpMessage, Message, Payload, RequestHead}; -use actix_router::{Path, Url, ResourceDef}; +use actix_router::{Path, Url}; use futures_util::future::{ok, Ready}; use tinyvec::TinyVec; @@ -139,7 +139,7 @@ impl HttpRequest { /// Checks if a given path matches a route #[inline] - pub fn match_name(&self) -> Option<&ResourceDef> { + pub fn match_name(&self) -> Option { self.0.rmap.match_name(&self.path()) } @@ -482,10 +482,10 @@ mod tests { .header(header::HOST, "www.rust-lang.org") .rmap(rmap) .to_http_request(); - let route_name = req.resource_map().match_name("index").unwrap().name(); + let route_name = req.0.rmap.match_name("index"); assert_eq!( - route_name, - rdef.name() + route_name.unwrap(), + rdef.name().to_owned() ); } @@ -645,8 +645,8 @@ mod tests { .service(web::resource("/profile").route(web::get().to( move |req: HttpRequest| { assert_eq!( - req.match_name(), - Some(&ResourceDef::new("/profile")) + req.0.rmap.match_name("/user/22/profile"), + Some(ResourceDef::new("/profile").name().to_owned()) ); HttpResponse::Ok().finish() diff --git a/src/rmap.rs b/src/rmap.rs index e0543e6cf..cb8476bd4 100644 --- a/src/rmap.rs +++ b/src/rmap.rs @@ -94,9 +94,14 @@ impl ResourceMap { } /// Returns the full resource pattern matched against a route or None if no match is /// found. - pub fn match_name(&self, path: &str) -> Option<&ResourceDef> { + pub fn match_name(&self, path: &str) -> Option { let path = if path.is_empty() { "/" } else { path }; - self.named.get(path) + let route = self.named.get(path); + + match route { + Some(route) => Some(route.name().to_string()), + None => None, + } } /// Returns the full resource pattern matched against a path or None if no full match diff --git a/src/service.rs b/src/service.rs index 775667a3d..eb1b1c4f0 100644 --- a/src/service.rs +++ b/src/service.rs @@ -198,7 +198,7 @@ impl ServiceRequest { /// Counterpart to [`HttpRequest::match_name`](../struct.HttpRequest.html#method.match_name). #[inline] - pub fn match_name(&self) -> Option<&ResourceDef> { + pub fn match_name(&self) -> Option { self.0.match_name() }