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