diff --git a/src/header/common/authorization.rs b/src/header/common/authorization.rs index af8efbdd5a..1dcc2b23f6 100644 --- a/src/header/common/authorization.rs +++ b/src/header/common/authorization.rs @@ -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 DerefMut for Authorization { } } -impl Header for Authorization where ::Err: 'static { +impl Header for Authorization where ::Err: 'static { fn header_name() -> &'static str { "Authorization" } @@ -43,7 +44,7 @@ impl Header for Authorization where ::Err: } } -impl HeaderFormat for Authorization where ::Err: 'static { +impl HeaderFormat for Authorization where ::Err: 'static { fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { match Scheme::scheme(None::) { Some(scheme) => try!(write!(fmt, "{} ", scheme)), diff --git a/src/net.rs b/src/net.rs index 1157514cc9..66dd705ce5 100644 --- a/src/net.rs +++ b/src/net.rs @@ -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(&self) -> bool { + pub fn is(&self) -> bool { self.get_type_id() == TypeId::of::() } /// If the underlying type is T, get a reference to the contained data. #[inline] - pub fn downcast_ref(&self) -> Option<&T> { + pub fn downcast_ref(&self) -> Option<&T> { if self.is::() { 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(&mut self) -> Option<&mut T> { + pub fn downcast_mut(&mut self) -> Option<&mut T> { if self.is::() { 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(self: Box) + pub fn downcast(self: Box) -> Result, Box> { if self.is::() { Ok(unsafe { self.downcast_unchecked() }) diff --git a/src/uri.rs b/src/uri.rs index a6a2aa344b..fac8506539 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -53,21 +53,21 @@ impl FromStr for RequestUri { type Err = HttpError; fn from_str(s: &str) -> Result { - 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())) } } }