Make the `uri` parameter in Request private.

This commit is contained in:
Sergio Benitez 2016-10-04 19:26:33 -07:00
parent f3b23b01d6
commit 650d079b58
4 changed files with 9 additions and 8 deletions

View File

@ -12,7 +12,7 @@ fn hello(name: &str, age: i8) -> String {
fn not_found(req: &rocket::Request) -> String {
format!("<p>Sorry, but '{}' is not a valid path!</p>
<p>Try visiting /hello/&lt;name&gt;/&lt;age&gt; instead.</p>",
req.uri)
req.uri())
}
fn main() {

View File

@ -132,8 +132,8 @@ impl<'a> From<&'a str> for URIBuf {
}
}
impl<'a> Collider for URI<'a> {
fn collides_with(&self, other: &URI) -> bool {
impl<'a, 'b> Collider<URI<'b>> for URI<'a> {
fn collides_with(&self, other: &URI<'b>) -> bool {
let mut trailing = false;
for (seg_a, seg_b) in self.segments().zip(other.segments()) {
if seg_a.ends_with("..>") || seg_b.ends_with("..>") {

View File

@ -23,8 +23,6 @@ use http::{Method, ContentType, Cookies};
pub struct Request<'a> {
/// The HTTP method associated with the request.
pub method: Method,
/// The URI associated with the request.
pub uri: URIBuf, // FIXME: Should be URI (without Hyper).
/// <div class="stability" style="margin-left: 0;">
/// <em class="stab unstable">
/// Unstable
@ -35,9 +33,12 @@ pub struct Request<'a> {
///
/// The data in the request.
pub data: Vec<u8>, // FIXME: Don't read this! (bad Hyper.)
uri: URIBuf, // FIXME: Should be URI (without Hyper).
cookies: Cookies,
headers: HyperHeaders, // This sucks.
params: RefCell<Option<Vec<&'a str>>>, // This also sucks.
/// Indexes into the URI.
// params: RefCell<Vec<(usize, usize)>>,
params: RefCell<Option<Vec<&'a str>>>,
}
impl<'a> Request<'a> {
@ -157,7 +158,7 @@ impl<'a> Request<'a> {
/// Retrieves the URI from the request. Rocket only allows absolute URIs, so
/// the URI will be absolute.
pub fn uri(&'a self) -> URI<'a> {
pub fn uri(&self) -> URI {
self.uri.as_uri()
}

View File

@ -125,7 +125,7 @@ impl Collider for Route {
impl<'r> Collider<Request<'r>> for Route {
fn collides_with(&self, req: &Request) -> bool {
self.method == req.method
&& req.uri.as_uri().collides_with(&self.path.as_uri())
&& req.uri().collides_with(&self.path.as_uri())
&& req.accepts().collides_with(&self.content_type)
}
}