mirror of https://github.com/rwf2/Rocket.git
Rename 'content_type' Route field to 'format'.
This commit is contained in:
parent
524a2d889d
commit
1f373cc83a
|
@ -201,7 +201,7 @@ mod tests {
|
|||
|
||||
fn ct_route(m: Method, s: &str, ct: &str) -> Route {
|
||||
let mut route_a = Route::new(m, s, dummy_handler);
|
||||
route_a.content_type = ContentType::from_str(ct).expect("Whoops!");
|
||||
route_a.format = ContentType::from_str(ct).expect("Whoops!");
|
||||
route_a
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ pub struct Route {
|
|||
/// The rank of this route. Lower ranks have higher priorities.
|
||||
pub rank: isize,
|
||||
/// The Content-Type this route matches against.
|
||||
pub content_type: ContentType,
|
||||
pub format: ContentType,
|
||||
}
|
||||
|
||||
fn default_rank(path: &str) -> isize {
|
||||
|
@ -45,7 +45,7 @@ impl Route {
|
|||
handler: handler,
|
||||
rank: default_rank(path.as_ref()),
|
||||
path: URI::from(path.as_ref().to_string()),
|
||||
content_type: ContentType::Any,
|
||||
format: ContentType::Any,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ impl Route {
|
|||
path: URI::from(path.as_ref().to_string()),
|
||||
handler: handler,
|
||||
rank: rank,
|
||||
content_type: ContentType::Any,
|
||||
format: ContentType::Any,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ impl Clone for Route {
|
|||
handler: self.handler,
|
||||
rank: self.rank,
|
||||
path: self.path.clone(),
|
||||
content_type: self.content_type.clone(),
|
||||
format: self.format.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,8 +114,8 @@ impl fmt::Display for Route {
|
|||
write!(f, " [{}]", White.paint(&self.rank))?;
|
||||
}
|
||||
|
||||
if !self.content_type.is_any() {
|
||||
write!(f, " {}", Yellow.paint(&self.content_type))
|
||||
if !self.format.is_any() {
|
||||
write!(f, " {}", Yellow.paint(&self.format))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ impl fmt::Debug for Route {
|
|||
impl<'a> From<&'a StaticRouteInfo> for Route {
|
||||
fn from(info: &'a StaticRouteInfo) -> Route {
|
||||
let mut route = Route::new(info.method, info.path, info.handler);
|
||||
route.content_type = info.format.clone().unwrap_or(ContentType::Any);
|
||||
route.format = info.format.clone().unwrap_or(ContentType::Any);
|
||||
if let Some(rank) = info.rank {
|
||||
route.rank = rank;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ impl Collider for Route {
|
|||
fn collides_with(&self, b: &Route) -> bool {
|
||||
self.method == b.method
|
||||
&& self.rank == b.rank
|
||||
&& self.content_type.collides_with(&b.content_type)
|
||||
&& self.format.collides_with(&b.format)
|
||||
&& self.path.collides_with(&b.path)
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +154,8 @@ impl<'r> Collider<Request<'r>> for Route {
|
|||
fn collides_with(&self, req: &Request<'r>) -> bool {
|
||||
self.method == req.method()
|
||||
&& req.uri().collides_with(&self.path)
|
||||
&& req.content_type().collides_with(&self.content_type)
|
||||
// FIXME: On payload requests, check Content-Type. On non-payload
|
||||
// requests, check Accept.
|
||||
&& req.content_type().collides_with(&self.format)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue