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