@@ -1,6 +1,7 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::{FromStr, from_utf8};
|
use std::str::{FromStr, from_utf8};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
use std::marker::Reflect;
|
||||||
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
|
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
|
||||||
use header::{Header, HeaderFormat};
|
use header::{Header, HeaderFormat};
|
||||||
|
|
||||||
@@ -22,7 +23,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Scheme + 'static> Header for Authorization<S> where <S as FromStr>::Err: 'static {
|
impl<S: Scheme + Reflect + 'static> Header for Authorization<S> where <S as FromStr>::Err: 'static {
|
||||||
fn header_name() -> &'static str {
|
fn header_name() -> &'static str {
|
||||||
"Authorization"
|
"Authorization"
|
||||||
}
|
}
|
||||||
@@ -43,7 +44,7 @@ impl<S: Scheme + 'static> Header for Authorization<S> where <S as FromStr>::Err:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Scheme + 'static> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
|
impl<S: Scheme + Reflect + 'static> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
|
||||||
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match Scheme::scheme(None::<S>) {
|
match Scheme::scheme(None::<S>) {
|
||||||
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
|
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use std::mem;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::raw::{self, TraitObject};
|
use std::raw::{self, TraitObject};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::marker::Reflect;
|
||||||
|
|
||||||
use openssl::ssl::{Ssl, SslStream, SslContext};
|
use openssl::ssl::{Ssl, SslStream, SslContext};
|
||||||
use openssl::ssl::SslVerifyMode::SslVerifyNone;
|
use openssl::ssl::SslVerifyMode::SslVerifyNone;
|
||||||
@@ -117,13 +118,13 @@ impl NetworkStream + Send {
|
|||||||
impl NetworkStream + Send {
|
impl NetworkStream + Send {
|
||||||
/// Is the underlying type in this trait object a T?
|
/// Is the underlying type in this trait object a T?
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is<T: 'static>(&self) -> bool {
|
pub fn is<T: Reflect + 'static>(&self) -> bool {
|
||||||
self.get_type_id() == TypeId::of::<T>()
|
self.get_type_id() == TypeId::of::<T>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the underlying type is T, get a reference to the contained data.
|
/// If the underlying type is T, get a reference to the contained data.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn downcast_ref<T: 'static>(&self) -> Option<&T> {
|
pub fn downcast_ref<T: Reflect + 'static>(&self) -> Option<&T> {
|
||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
Some(unsafe { self.downcast_ref_unchecked() })
|
Some(unsafe { self.downcast_ref_unchecked() })
|
||||||
} else {
|
} else {
|
||||||
@@ -134,7 +135,7 @@ impl NetworkStream + Send {
|
|||||||
/// If the underlying type is T, get a mutable reference to the contained
|
/// If the underlying type is T, get a mutable reference to the contained
|
||||||
/// data.
|
/// data.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> {
|
pub fn downcast_mut<T: Reflect + 'static>(&mut self) -> Option<&mut T> {
|
||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
Some(unsafe { self.downcast_mut_unchecked() })
|
Some(unsafe { self.downcast_mut_unchecked() })
|
||||||
} else {
|
} else {
|
||||||
@@ -143,7 +144,7 @@ impl NetworkStream + Send {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// If the underlying type is T, extract it.
|
/// If the underlying type is T, extract it.
|
||||||
pub fn downcast<T: 'static>(self: Box<NetworkStream + Send>)
|
pub fn downcast<T: Reflect + 'static>(self: Box<NetworkStream + Send>)
|
||||||
-> Result<Box<T>, Box<NetworkStream + Send>> {
|
-> Result<Box<T>, Box<NetworkStream + Send>> {
|
||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
Ok(unsafe { self.downcast_unchecked() })
|
Ok(unsafe { self.downcast_unchecked() })
|
||||||
|
|||||||
30
src/uri.rs
30
src/uri.rs
@@ -53,21 +53,21 @@ impl FromStr for RequestUri {
|
|||||||
type Err = HttpError;
|
type Err = HttpError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<RequestUri, HttpError> {
|
fn from_str(s: &str) -> Result<RequestUri, HttpError> {
|
||||||
match s.as_bytes() {
|
let bytes = s.as_bytes();
|
||||||
[] => Err(HttpError::HttpUriError(UrlError::InvalidCharacter)),
|
if bytes == [] {
|
||||||
[b'*'] => Ok(RequestUri::Star),
|
Err(HttpError::HttpUriError(UrlError::InvalidCharacter))
|
||||||
[b'/', ..] => Ok(RequestUri::AbsolutePath(s.to_string())),
|
} else if bytes == b"*" {
|
||||||
bytes if bytes.contains(&b'/') => {
|
Ok(RequestUri::Star)
|
||||||
Ok(RequestUri::AbsoluteUri(try!(Url::parse(s))))
|
} else if bytes.starts_with(b"/") {
|
||||||
}
|
Ok(RequestUri::AbsolutePath(s.to_string()))
|
||||||
_ => {
|
} else if bytes.contains(&b'/') {
|
||||||
let mut temp = "http://".to_string();
|
Ok(RequestUri::AbsoluteUri(try!(Url::parse(s))))
|
||||||
temp.push_str(s);
|
} else {
|
||||||
try!(Url::parse(&temp[..]));
|
let mut temp = "http://".to_string();
|
||||||
todo!("compare vs u.authority()");
|
temp.push_str(s);
|
||||||
Ok(RequestUri::Authority(s.to_string()))
|
try!(Url::parse(&temp[..]));
|
||||||
}
|
todo!("compare vs u.authority()");
|
||||||
|
Ok(RequestUri::Authority(s.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user