diff --git a/codegen/src/macros/uri.rs b/codegen/src/macros/uri.rs index 3816b951..c25c8432 100644 --- a/codegen/src/macros/uri.rs +++ b/codegen/src/macros/uri.rs @@ -137,6 +137,6 @@ pub fn uri_internal( MacEager::expr(quote_expr!(ecx, { $argument_stmts - ::rocket::http::uri::URI::from(format!($fmt_string, $format_assign_tokens)) + ::rocket::http::uri::Uri::from(format!($fmt_string, $format_assign_tokens)) })) } diff --git a/codegen/src/parser/route.rs b/codegen/src/parser/route.rs index 482cc8a7..bc0ded6d 100644 --- a/codegen/src/parser/route.rs +++ b/codegen/src/parser/route.rs @@ -10,7 +10,7 @@ use super::Function; use super::keyvalue::KVSpanned; use super::uri::validate_uri; use rocket::http::{Method, MediaType}; -use rocket::http::uri::URI; +use rocket::http::uri::Uri; /// This structure represents the parsed `route` attribute. /// @@ -22,7 +22,7 @@ use rocket::http::uri::URI; pub struct RouteParams { pub annotated_fn: Function, pub method: Spanned, - pub uri: Spanned>, + pub uri: Spanned>, pub data_param: Option>, pub query_param: Option>, pub format: Option>, @@ -185,7 +185,7 @@ fn parse_method(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned { fn parse_path(ecx: &ExtCtxt, meta_item: &NestedMetaItem) - -> (Spanned>, Option>) { + -> (Spanned>, Option>) { let sp = meta_item.span(); if let Some((name, lit)) = meta_item.name_value() { if name != &"path" { @@ -205,7 +205,7 @@ fn parse_path(ecx: &ExtCtxt, .emit(); } - (dummy_spanned(URI::new("")), None) + (dummy_spanned(Uri::new("")), None) } fn parse_opt(ecx: &ExtCtxt, kv: &KVSpanned, f: F) -> Option> diff --git a/codegen/src/parser/uri.rs b/codegen/src/parser/uri.rs index feebeed9..bd137881 100644 --- a/codegen/src/parser/uri.rs +++ b/codegen/src/parser/uri.rs @@ -2,7 +2,7 @@ use syntax::ast::*; use syntax::codemap::{Span, Spanned, dummy_spanned}; use syntax::ext::base::ExtCtxt; -use rocket::http::uri::URI; +use rocket::http::uri::Uri; use super::route::param_to_ident; use utils::{span, SpanExt, is_valid_ident}; @@ -11,7 +11,7 @@ use utils::{span, SpanExt, is_valid_ident}; // stripped out at runtime. So, to avoid any confusion, we issue an error at // compile-time for empty segments. At the moment, this disallows trailing // slashes as well, since then the last segment is empty. -fn valid_path(ecx: &ExtCtxt, uri: &URI, sp: Span) -> bool { +fn valid_path(ecx: &ExtCtxt, uri: &Uri, sp: Span) -> bool { let cleaned = uri.to_string(); if !uri.as_str().starts_with('/') { ecx.struct_span_err(sp, "route paths must be absolute") @@ -28,7 +28,7 @@ fn valid_path(ecx: &ExtCtxt, uri: &URI, sp: Span) -> bool { false } -fn valid_segments(ecx: &ExtCtxt, uri: &URI, sp: Span) -> bool { +fn valid_segments(ecx: &ExtCtxt, uri: &Uri, sp: Span) -> bool { let mut validated = true; let mut segments_span = None; for segment in uri.segments() { @@ -81,7 +81,7 @@ fn valid_segments(ecx: &ExtCtxt, uri: &URI, sp: Span) -> bool { } validated = false; - } else if URI::percent_encode(segment) != segment { + } else if Uri::percent_encode(segment) != segment { if segment.contains("<") || segment.contains(">") { ecx.struct_span_err(span, "malformed parameter") .help("parameters must be of the form ''") @@ -100,8 +100,8 @@ fn valid_segments(ecx: &ExtCtxt, uri: &URI, sp: Span) -> bool { pub fn validate_uri(ecx: &ExtCtxt, string: &str, sp: Span) - -> (Spanned>, Option>) { - let uri = URI::from(string.to_string()); + -> (Spanned>, Option>) { + let uri = Uri::from(string.to_string()); let query_param = string.find('?') .map(|i| span(&string[(i + 1)..], sp.trim_left(i + 1))) .and_then(|spanned_q_param| param_to_ident(ecx, spanned_q_param)); @@ -109,6 +109,6 @@ pub fn validate_uri(ecx: &ExtCtxt, if valid_segments(ecx, &uri, sp) && valid_path(ecx, &uri, sp) { (span(uri, sp), query_param) } else { - (dummy_spanned(URI::new("")), query_param) + (dummy_spanned(Uri::new("")), query_param) } } diff --git a/codegen/tests/typed-uris.rs b/codegen/tests/typed-uris.rs index a9730288..0e32f045 100644 --- a/codegen/tests/typed-uris.rs +++ b/codegen/tests/typed-uris.rs @@ -7,7 +7,7 @@ extern crate rocket; use std::fmt; use rocket::http::{RawStr, Cookies}; -use rocket::http::uri::{URI, UriDisplay}; +use rocket::http::uri::{Uri, UriDisplay}; use rocket::request::Form; #[derive(FromForm)] @@ -71,7 +71,7 @@ fn complex<'r>( ) -> &'static str { "" } macro assert_uri_eq($($uri:expr => $expected:expr,)+) { - $(assert_eq!($uri, URI::from($expected));)+ + $(assert_eq!($uri, Uri::from($expected));)+ } #[test] diff --git a/lib/src/http/uri.rs b/lib/src/http/uri.rs index 83eb913a..3ae73656 100644 --- a/lib/src/http/uri.rs +++ b/lib/src/http/uri.rs @@ -19,7 +19,7 @@ const EMPTY: isize = -1; // TODO: Reconsider deriving PartialEq and Eq to make "//a/b" == "/a/b". /// Borrowed string type for absolute URIs. #[derive(Debug)] -pub struct URI<'a> { +pub struct Uri<'a> { uri: Cow<'a, str>, path: Index, query: Option, @@ -28,10 +28,10 @@ pub struct URI<'a> { segment_count: AtomicIsize, } -impl<'a> URI<'a> { +impl<'a> Uri<'a> { /// Constructs a new URI from a given string. The URI is assumed to be an /// absolute, well formed URI. - pub fn new>>(uri: T) -> URI<'a> { + pub fn new>>(uri: T) -> Uri<'a> { let uri = uri.into(); let qmark = uri.find('?'); let hmark = uri.find('#'); @@ -44,7 +44,7 @@ impl<'a> URI<'a> { (None, None) => ((0, end), None, None), }; - URI { + Uri { uri: uri, path: path, query: query, @@ -64,18 +64,18 @@ impl<'a> URI<'a> { /// A valid URI with only non-empty segments: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b/c"); + /// let uri = Uri::new("/a/b/c"); /// assert_eq!(uri.segment_count(), 3); /// ``` /// /// A URI with empty segments: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b//c/d///e"); + /// let uri = Uri::new("/a/b//c/d///e"); /// assert_eq!(uri.segment_count(), 5); /// ``` #[inline(always)] @@ -101,9 +101,9 @@ impl<'a> URI<'a> { /// A valid URI with only non-empty segments: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b/c?a=true#done"); + /// let uri = Uri::new("/a/b/c?a=true#done"); /// for (i, segment) in uri.segments().enumerate() { /// match i { /// 0 => assert_eq!(segment, "a"), @@ -117,9 +117,9 @@ impl<'a> URI<'a> { /// A URI with empty segments: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("///a//b///c////d?#"); + /// let uri = Uri::new("///a//b///c////d?#"); /// for (i, segment) in uri.segments().enumerate() { /// match i { /// 0 => assert_eq!(segment, "a"), @@ -142,18 +142,18 @@ impl<'a> URI<'a> { /// A URI with only a path: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b/c"); + /// let uri = Uri::new("/a/b/c"); /// assert_eq!(uri.path(), "/a/b/c"); /// ``` /// /// A URI with other components: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b/c?name=bob#done"); + /// let uri = Uri::new("/a/b/c?name=bob#done"); /// assert_eq!(uri.path(), "/a/b/c"); /// ``` #[inline(always)] @@ -170,18 +170,18 @@ impl<'a> URI<'a> { /// A URI with a query part: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b/c?alphabet=true"); + /// let uri = Uri::new("/a/b/c?alphabet=true"); /// assert_eq!(uri.query(), Some("alphabet=true")); /// ``` /// /// A URI without the query part: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b/c"); + /// let uri = Uri::new("/a/b/c"); /// assert_eq!(uri.query(), None); /// ``` #[inline(always)] @@ -197,18 +197,18 @@ impl<'a> URI<'a> { /// A URI with a fragment part: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a?alphabet=true#end"); + /// let uri = Uri::new("/a?alphabet=true#end"); /// assert_eq!(uri.fragment(), Some("end")); /// ``` /// /// A URI without the fragment part: /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a?query=true"); + /// let uri = Uri::new("/a?query=true"); /// assert_eq!(uri.fragment(), None); /// ``` #[inline(always)] @@ -222,10 +222,10 @@ impl<'a> URI<'a> { /// # Examples /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/Hello%2C%20world%21"); - /// let decoded_path = URI::percent_decode(uri.path().as_bytes()).expect("decoded"); + /// let uri = Uri::new("/Hello%2C%20world%21"); + /// let decoded_path = Uri::percent_decode(uri.path().as_bytes()).expect("decoded"); /// assert_eq!(decoded_path, "/Hello, world!"); /// ``` pub fn percent_decode(string: &[u8]) -> Result, Utf8Error> { @@ -240,10 +240,10 @@ impl<'a> URI<'a> { /// # Examples /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/Hello%2C%20world%21"); - /// let decoded_path = URI::percent_decode_lossy(uri.path().as_bytes()); + /// let uri = Uri::new("/Hello%2C%20world%21"); + /// let decoded_path = Uri::percent_decode_lossy(uri.path().as_bytes()); /// assert_eq!(decoded_path, "/Hello, world!"); /// ``` pub fn percent_decode_lossy(string: &[u8]) -> Cow { @@ -258,9 +258,9 @@ impl<'a> URI<'a> { /// # Examples /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let encoded = URI::percent_encode("hello?a=hi"); + /// let encoded = Uri::percent_encode("hello?a=hi"); /// assert_eq!(encoded, "hello%3Fa=%3Cb%3Ehi%3C%2Fb%3E"); /// ``` pub fn percent_encode(string: &str) -> Cow { @@ -276,9 +276,9 @@ impl<'a> URI<'a> { /// ### Example /// /// ```rust - /// use rocket::http::uri::URI; + /// use rocket::http::uri::Uri; /// - /// let uri = URI::new("/a/b///c/d/e//f?name=Mike#end"); + /// let uri = Uri::new("/a/b///c/d/e//f?name=Mike#end"); /// assert_eq!(uri.as_str(), "/a/b///c/d/e//f?name=Mike#end"); /// ``` #[inline(always)] @@ -287,10 +287,10 @@ impl<'a> URI<'a> { } } -impl<'a> Clone for URI<'a> { +impl<'a> Clone for Uri<'a> { #[inline(always)] - fn clone(&self) -> URI<'a> { - URI { + fn clone(&self) -> Uri<'a> { + Uri { uri: self.uri.clone(), path: self.path, query: self.query, @@ -300,32 +300,32 @@ impl<'a> Clone for URI<'a> { } } -impl<'a, 'b> PartialEq> for URI<'a> { +impl<'a, 'b> PartialEq> for Uri<'a> { #[inline] - fn eq(&self, other: &URI<'b>) -> bool { + fn eq(&self, other: &Uri<'b>) -> bool { self.path() == other.path() && self.query() == other.query() && self.fragment() == other.fragment() } } -impl<'a> Eq for URI<'a> {} +impl<'a> Eq for Uri<'a> {} -impl<'a> From<&'a str> for URI<'a> { +impl<'a> From<&'a str> for Uri<'a> { #[inline(always)] - fn from(uri: &'a str) -> URI<'a> { - URI::new(uri) + fn from(uri: &'a str) -> Uri<'a> { + Uri::new(uri) } } -impl From for URI<'static> { +impl From for Uri<'static> { #[inline(always)] - fn from(uri: String) -> URI<'static> { - URI::new(uri) + fn from(uri: String) -> Uri<'static> { + Uri::new(uri) } } -impl<'a> fmt::Display for URI<'a> { +impl<'a> fmt::Display for Uri<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // If this is the root path, then there are "zero" segments. if self.segment_count() == 0 { @@ -427,9 +427,9 @@ impl<'a> fmt::Display for URI<'a> { /// When manually implementing `UriDisplay` for your types, you should defer to /// existing implementations of `UriDisplay` as much as possible. In the example /// below, for instance, `Name`'s implementation defers to `String`'s -/// implementation. To percent-encode a string, use [`URI::percent_encode()`]. +/// implementation. To percent-encode a string, use [`Uri::percent_encode()`]. /// -/// [`URI::percent_encode()`]: https://api.rocket.rs/rocket/http/uri/struct.URI.html#method.percent_encode +/// [`Uri::percent_encode()`]: https://api.rocket.rs/rocket/http/uri/struct.Uri.html#method.percent_encode /// /// ## Example /// @@ -586,7 +586,7 @@ impl<'a> fmt::Display for &'a UriDisplay { impl<'a> UriDisplay for &'a RawStr { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", URI::percent_encode((*self).as_str())) + write!(f, "{}", Uri::percent_encode((*self).as_str())) } } @@ -594,7 +594,7 @@ impl<'a> UriDisplay for &'a RawStr { impl<'a> UriDisplay for &'a str { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", URI::percent_encode(self)) + write!(f, "{}", Uri::percent_encode(self)) } } @@ -602,7 +602,7 @@ impl<'a> UriDisplay for &'a str { impl<'a> UriDisplay for Cow<'a, str> { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", URI::percent_encode(self)) + write!(f, "{}", Uri::percent_encode(self)) } } @@ -610,7 +610,7 @@ impl<'a> UriDisplay for Cow<'a, str> { impl UriDisplay for String { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", URI::percent_encode(self.as_str())) + write!(f, "{}", Uri::percent_encode(self.as_str())) } } @@ -652,9 +652,9 @@ impl_for_ref!(&'a mut T, &'a T); /// ### Examples /// /// ```rust -/// use rocket::http::uri::URI; +/// use rocket::http::uri::Uri; /// -/// let uri = URI::new("/a/////b/c////////d"); +/// let uri = Uri::new("/a/////b/c////////d"); /// let segments = uri.segments(); /// for (i, segment) in segments.enumerate() { /// match i { @@ -716,15 +716,15 @@ pub enum SegmentError { #[cfg(test)] mod tests { - use super::URI; + use super::Uri; fn seg_count(path: &str, expected: usize) -> bool { - let actual = URI::new(path).segment_count(); + let actual = Uri::new(path).segment_count(); if actual != expected { trace_!("Count mismatch: expected {}, got {}.", expected, actual); trace_!("{}", if actual != expected { "lifetime" } else { "buf" }); trace_!("Segments (for {}):", path); - for (i, segment) in URI::new(path).segments().enumerate() { + for (i, segment) in Uri::new(path).segments().enumerate() { trace_!("{}: {}", i, segment); } } @@ -733,7 +733,7 @@ mod tests { } fn eq_segments(path: &str, expected: &[&str]) -> bool { - let uri = URI::new(path); + let uri = Uri::new(path); let actual: Vec<&str> = uri.segments().collect(); actual == expected } @@ -741,7 +741,7 @@ mod tests { #[test] fn send_and_sync() { fn assert() {}; - assert::(); + assert::(); } #[test] @@ -830,12 +830,12 @@ mod tests { } fn test_query(uri: &str, query: Option<&str>) { - let uri = URI::new(uri); + let uri = Uri::new(uri); assert_eq!(uri.query(), query); } fn test_fragment(uri: &str, fragment: Option<&str>) { - let uri = URI::new(uri); + let uri = Uri::new(uri); assert_eq!(uri.fragment(), fragment); } @@ -877,7 +877,7 @@ mod tests { #[test] fn to_string() { - let uri_to_string = |string| URI::new(string).to_string(); + let uri_to_string = |string| Uri::new(string).to_string(); assert_eq!(uri_to_string("/"), "/".to_string()); assert_eq!(uri_to_string("//"), "/".to_string()); diff --git a/lib/src/local/client.rs b/lib/src/local/client.rs index ad958fb6..4f9297f8 100644 --- a/lib/src/local/client.rs +++ b/lib/src/local/client.rs @@ -1,7 +1,7 @@ use {Rocket, Request}; use local::LocalRequest; use http::Method; -use http::uri::URI; +use http::uri::Uri; use error::LaunchError; /// A structure to construct requests for local dispatching. @@ -99,7 +99,7 @@ impl Client { /// let req = client.get("/hello"); /// ``` #[inline(always)] - pub fn get<'c, 'u: 'c, U: Into>>(&'c self, uri: U) -> LocalRequest<'c> { + pub fn get<'c, 'u: 'c, U: Into>>(&'c self, uri: U) -> LocalRequest<'c> { self.req(Method::Get, uri) } @@ -120,7 +120,7 @@ impl Client { /// let req = client.put("/hello"); /// ``` #[inline(always)] - pub fn put<'c, 'u: 'c, U: Into>>(&'c self, uri: U) -> LocalRequest<'c> { + pub fn put<'c, 'u: 'c, U: Into>>(&'c self, uri: U) -> LocalRequest<'c> { self.req(Method::Put, uri) } @@ -145,7 +145,7 @@ impl Client { /// .header(ContentType::Form); /// ``` #[inline(always)] - pub fn post<'c, 'u: 'c, U: Into>>(&'c self, uri: U) -> LocalRequest<'c> { + pub fn post<'c, 'u: 'c, U: Into>>(&'c self, uri: U) -> LocalRequest<'c> { self.req(Method::Post, uri) } @@ -167,7 +167,7 @@ impl Client { /// ``` #[inline(always)] pub fn delete<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> - where U: Into> + where U: Into> { self.req(Method::Delete, uri) } @@ -190,7 +190,7 @@ impl Client { /// ``` #[inline(always)] pub fn options<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> - where U: Into> + where U: Into> { self.req(Method::Options, uri) } @@ -213,7 +213,7 @@ impl Client { /// ``` #[inline(always)] pub fn head<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> - where U: Into> + where U: Into> { self.req(Method::Head, uri) } @@ -236,7 +236,7 @@ impl Client { /// ``` #[inline(always)] pub fn patch<'c, 'u: 'c, U>(&'c self, uri: U) -> LocalRequest<'c> - where U: Into> + where U: Into> { self.req(Method::Patch, uri) } @@ -260,7 +260,7 @@ impl Client { /// ``` #[inline(always)] pub fn req<'c, 'u: 'c, U>(&'c self, method: Method, uri: U) -> LocalRequest<'c> - where U: Into> + where U: Into> { let request = Request::new(&self.rocket, method, uri); LocalRequest::new(&self.rocket, request) diff --git a/lib/src/request/from_request.rs b/lib/src/request/from_request.rs index 1cdc9323..ed85a3d9 100644 --- a/lib/src/request/from_request.rs +++ b/lib/src/request/from_request.rs @@ -7,7 +7,7 @@ use outcome::{self, IntoOutcome}; use outcome::Outcome::*; use http::{Status, ContentType, Accept, Method, Cookies}; -use http::uri::URI; +use http::uri::Uri; /// Type alias for the `Outcome` of a `FromRequest` conversion. pub type Outcome = outcome::Outcome; @@ -104,7 +104,7 @@ impl IntoOutcome for Result { /// /// * **&URI** /// -/// Extracts the [URI](/rocket/http/uri/struct.URI.html) from the incoming +/// Extracts the [`Uri`](/rocket/http/uri/struct.Uri.html) from the incoming /// request. /// /// _This implementation always returns successfully._ @@ -229,7 +229,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for Method { } } -impl<'a, 'r> FromRequest<'a, 'r> for &'a URI<'a> { +impl<'a, 'r> FromRequest<'a, 'r> for &'a Uri<'a> { type Error = (); fn from_request(request: &'a Request<'r>) -> Outcome { diff --git a/lib/src/request/param.rs b/lib/src/request/param.rs index 8f426470..227261c0 100644 --- a/lib/src/request/param.rs +++ b/lib/src/request/param.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use std::fmt::Debug; use std::borrow::Cow; -use http::uri::{URI, Segments, SegmentError}; +use http::uri::{Uri, Segments, SegmentError}; use http::RawStr; /// Trait to convert a dynamic path segment string to a concrete value. @@ -325,7 +325,7 @@ impl<'a> FromSegments<'a> for PathBuf { fn from_segments(segments: Segments<'a>) -> Result { let mut buf = PathBuf::new(); for segment in segments { - let decoded = URI::percent_decode(segment.as_bytes()) + let decoded = Uri::percent_decode(segment.as_bytes()) .map_err(|e| SegmentError::Utf8(e))?; if decoded == ".." { diff --git a/lib/src/request/request.rs b/lib/src/request/request.rs index 6fc01d5e..f0492def 100644 --- a/lib/src/request/request.rs +++ b/lib/src/request/request.rs @@ -11,7 +11,7 @@ use super::{FromParam, FromSegments, FromRequest, Outcome}; use rocket::Rocket; use router::Route; use config::{Config, Limits}; -use http::uri::{URI, Segments}; +use http::uri::{Uri, Segments}; use error::Error; use http::{Method, Header, HeaderMap, Cookies, CookieJar}; use http::{RawStr, ContentType, Accept, MediaType}; @@ -38,7 +38,7 @@ struct RequestState<'r> { #[derive(Clone)] pub struct Request<'r> { method: Method, - uri: URI<'r>, + uri: Uri<'r>, headers: HeaderMap<'r>, remote: Option, state: RequestState<'r> @@ -46,10 +46,10 @@ pub struct Request<'r> { impl<'r> Request<'r> { /// Create a new `Request` with the given `method` and `uri`. The `uri` - /// parameter can be of any type that implements `Into` including + /// parameter can be of any type that implements `Into` including /// `&str` and `String`; it must be a valid absolute URI. #[inline(always)] - pub(crate) fn new<'s: 'r, U: Into>>(rocket: &'r Rocket, + pub(crate) fn new<'s: 'r, U: Into>>(rocket: &'r Rocket, method: Method, uri: U) -> Request<'r> { Request { @@ -126,12 +126,12 @@ impl<'r> Request<'r> { /// # }); /// ``` #[inline(always)] - pub fn uri(&self) -> &URI { + pub fn uri(&self) -> &Uri { &self.uri } /// Set the URI in `self`. The `uri` parameter can be of any type that - /// implements `Into` including `&str` and `String`; it _must_ be a + /// implements `Into` including `&str` and `String`; it _must_ be a /// valid, absolute URI. /// /// # Example @@ -145,7 +145,7 @@ impl<'r> Request<'r> { /// # }); /// ``` #[inline(always)] - pub fn set_uri<'u: 'r, U: Into>>(&mut self, uri: U) { + pub fn set_uri<'u: 'r, U: Into>>(&mut self, uri: U) { self.uri = uri.into(); *self.state.params.borrow_mut() = Vec::new(); } diff --git a/lib/src/rocket.rs b/lib/src/rocket.rs index 32ca0465..1af7230d 100644 --- a/lib/src/rocket.rs +++ b/lib/src/rocket.rs @@ -23,7 +23,7 @@ use fairing::{Fairing, Fairings}; use http::{Method, Status, Header}; use http::hyper::{self, header}; -use http::uri::URI; +use http::uri::Uri; /// The main `Rocket` type: used to mount routes and catchers and launch the /// application. @@ -57,7 +57,7 @@ impl hyper::Handler for Rocket { Ok(req) => req, Err(e) => { error!("Bad incoming request: {}", e); - let dummy = Request::new(self, Method::Get, URI::new("")); + let dummy = Request::new(self, Method::Get, Uri::new("")); let r = self.handle_error(Status::InternalServerError, &dummy); return self.issue_response(r, res); } @@ -497,7 +497,7 @@ impl Rocket { } for mut route in routes { - let uri = URI::new(format!("{}/{}", base, route.uri)); + let uri = Uri::new(format!("{}/{}", base, route.uri)); route.set_base(base); route.set_uri(uri.to_string()); diff --git a/lib/src/router/collider.rs b/lib/src/router/collider.rs index e64b424f..312aa32a 100644 --- a/lib/src/router/collider.rs +++ b/lib/src/router/collider.rs @@ -1,6 +1,6 @@ use super::Route; -use http::uri::URI; +use http::uri::Uri; use http::MediaType; use request::Request; @@ -53,8 +53,8 @@ impl<'a> Collider for &'a str { } // This _only_ checks the `path` component of the URI. -impl<'a, 'b> Collider> for URI<'a> { - fn collides_with(&self, other: &URI<'b>) -> bool { +impl<'a, 'b> Collider> for Uri<'a> { + fn collides_with(&self, other: &Uri<'b>) -> bool { for (seg_a, seg_b) in self.segments().zip(other.segments()) { if seg_a.ends_with("..>") || seg_b.ends_with("..>") { return true; @@ -138,7 +138,7 @@ mod tests { use handler::Outcome; use router::route::Route; use http::{Method, MediaType, ContentType, Accept}; - use http::uri::URI; + use http::uri::Uri; use http::Method::*; type SimpleRoute = (Method, &'static str); @@ -158,7 +158,7 @@ mod tests { } fn s_s_collide(a: &'static str, b: &'static str) -> bool { - URI::new(a).collides_with(&URI::new(b)) + Uri::new(a).collides_with(&Uri::new(b)) } #[test] diff --git a/lib/src/router/mod.rs b/lib/src/router/mod.rs index 8e6c8786..7ee17156 100644 --- a/lib/src/router/mod.rs +++ b/lib/src/router/mod.rs @@ -78,7 +78,7 @@ mod test { use config::Config; use http::Method; use http::Method::*; - use http::uri::URI; + use http::uri::Uri; use request::Request; use data::Data; use handler::Outcome; @@ -166,7 +166,7 @@ mod test { fn route<'a>(router: &'a Router, method: Method, uri: &str) -> Option<&'a Route> { let rocket = Rocket::custom(Config::development().unwrap(), true); - let request = Request::new(&rocket, method, URI::new(uri)); + let request = Request::new(&rocket, method, Uri::new(uri)); let matches = router.route(&request); if matches.len() > 0 { Some(matches[0]) @@ -177,7 +177,7 @@ mod test { fn matches<'a>(router: &'a Router, method: Method, uri: &str) -> Vec<&'a Route> { let rocket = Rocket::custom(Config::development().unwrap(), true); - let request = Request::new(&rocket, method, URI::new(uri)); + let request = Request::new(&rocket, method, Uri::new(uri)); router.route(&request) } @@ -404,7 +404,7 @@ mod test { fn match_params(router: &Router, path: &str, expected: &[&str]) -> bool { println!("Testing: {} (expect: {:?})", path, expected); route(router, Get, path).map_or(false, |route| { - let params = route.get_param_indexes(&URI::new(path)); + let params = route.get_param_indexes(&Uri::new(path)); if params.len() != expected.len() { return false; } diff --git a/lib/src/router/route.rs b/lib/src/router/route.rs index 0cce839f..349f3108 100644 --- a/lib/src/router/route.rs +++ b/lib/src/router/route.rs @@ -6,7 +6,7 @@ use yansi::Color::*; use codegen::StaticRouteInfo; use handler::Handler; use http::{Method, MediaType}; -use http::uri::URI; +use http::uri::Uri; /// A route: a method, its handler, path, rank, and format/media type. pub struct Route { @@ -17,10 +17,10 @@ pub struct Route { /// The function that should be called when the route matches. pub handler: Handler, /// The base mount point of this `Route`. - pub base: URI<'static>, + pub base: Uri<'static>, /// The uri (in Rocket format) that should be matched against. This uri /// already includes the base mount point. - pub uri: URI<'static>, + pub uri: Uri<'static>, /// The rank of this route. Lower ranks have higher priorities. pub rank: isize, /// The media type this route matches against, if any. @@ -28,7 +28,7 @@ pub struct Route { } #[inline(always)] -fn default_rank(uri: &URI) -> isize { +fn default_rank(uri: &Uri) -> isize { // static path, query = -4; static path, no query = -3 // dynamic path, query = -2; dynamic path, no query = -1 match (!uri.path().contains('<'), uri.query().is_some()) { @@ -80,13 +80,13 @@ impl Route { pub fn new(m: Method, path: S, handler: Handler) -> Route where S: AsRef { - let uri = URI::from(path.as_ref().to_string()); + let uri = Uri::from(path.as_ref().to_string()); Route { name: None, method: m, handler: handler, rank: default_rank(&uri), - base: URI::from("/"), + base: Uri::from("/"), uri: uri, format: None, } @@ -116,8 +116,8 @@ impl Route { name: None, method: m, handler: handler, - base: URI::from("/"), - uri: URI::from(uri.as_ref().to_string()), + base: Uri::from("/"), + uri: Uri::from(uri.as_ref().to_string()), rank: rank, format: None, } @@ -168,7 +168,7 @@ impl Route { /// assert_eq!(index.base.path(), "/hi"); /// ``` pub fn set_base(&mut self, path: S) where S: AsRef { - self.base = URI::from(path.as_ref().to_string()); + self.base = Uri::from(path.as_ref().to_string()); } /// Sets the path of the route. Does not update the rank or any other @@ -192,7 +192,7 @@ impl Route { /// assert_eq!(index.uri.path(), "/hello"); /// ``` pub fn set_uri(&mut self, uri: S) where S: AsRef { - self.uri = URI::from(uri.as_ref().to_string()); + self.uri = Uri::from(uri.as_ref().to_string()); } // FIXME: Decide whether a component has to be fully variable or not. That @@ -200,7 +200,7 @@ impl Route { // TODO: Don't return a Vec...take in an &mut [&'a str] (no alloc!) /// Given a URI, returns a vector of slices of that URI corresponding to the /// dynamic segments in this route. - pub(crate) fn get_param_indexes(&self, uri: &URI) -> Vec<(usize, usize)> { + pub(crate) fn get_param_indexes(&self, uri: &Uri) -> Vec<(usize, usize)> { let route_segs = self.uri.segments(); let uri_segs = uri.segments(); let start_addr = uri.path().as_ptr() as usize;