Merge pull request #493 from pyfisch/nice
refactor(hyper): Fix a few nits
This commit is contained in:
		| @@ -52,9 +52,8 @@ impl header::Header for AccessControlAllowOrigin { | ||||
| impl header::HeaderFormat for AccessControlAllowOrigin { | ||||
|     fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match *self { | ||||
|             AccessControlAllowOrigin::Any => write!(f, "*"), | ||||
|             AccessControlAllowOrigin::Value(ref url) => | ||||
|                 write!(f, "{}", url) | ||||
|             AccessControlAllowOrigin::Any => f.write_str("*"), | ||||
|             AccessControlAllowOrigin::Value(ref url) => fmt::Display::fmt(url, f) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -45,12 +45,11 @@ impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'st | ||||
| } | ||||
|  | ||||
| impl<S: Scheme + Any> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static { | ||||
|     fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||||
|         match <S as Scheme>::scheme() { | ||||
|             Some(scheme) => try!(write!(fmt, "{} ", scheme)), | ||||
|             None => () | ||||
|     fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         if let Some(scheme) = <S as Scheme>::scheme() { | ||||
|             try!(write!(f, "{} ", scheme)) | ||||
|         }; | ||||
|         self.0.fmt_scheme(fmt) | ||||
|         self.0.fmt_scheme(f) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -70,7 +69,7 @@ impl Scheme for String { | ||||
|     } | ||||
|  | ||||
|     fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(f, "{}", self) | ||||
|         fmt::Display::fmt(self, f) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -190,4 +189,3 @@ mod tests { | ||||
|  | ||||
| bench_header!(raw, Authorization<String>, { vec![b"foo bar baz".to_vec()] }); | ||||
| bench_header!(basic, Authorization<Basic>, { vec![b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()] }); | ||||
|  | ||||
|   | ||||
| @@ -19,7 +19,7 @@ impl Header for CacheControl { | ||||
|             .filter_map(|line| from_one_comma_delimited(&line[..])) | ||||
|             .collect::<Vec<Vec<CacheDirective>>>() | ||||
|             .concat(); | ||||
|         if directives.len() > 0 { | ||||
|         if !directives.is_empty() { | ||||
|             Some(CacheControl(directives)) | ||||
|         } else { | ||||
|             None | ||||
|   | ||||
| @@ -33,7 +33,6 @@ impl Header for Pragma { | ||||
|         parsing::from_one_raw_str(raw).and_then(|s: String| { | ||||
|             let slice = &s.to_ascii_lowercase()[..]; | ||||
|             match slice { | ||||
|                 "" => None, | ||||
|                 "no-cache" => Some(Pragma::NoCache), | ||||
|                 _ => Some(Pragma::Ext(s)), | ||||
|             } | ||||
| @@ -58,4 +57,6 @@ fn test_parse_header() { | ||||
|     let c: Pragma = Header::parse_header([b"FoObar".to_vec()].as_ref()).unwrap(); | ||||
|     let d = Pragma::Ext("FoObar".to_string()); | ||||
|     assert_eq!(c, d); | ||||
|     let e: Option<Pragma> = Header::parse_header([b"".to_vec()].as_ref()); | ||||
|     assert_eq!(e, None); | ||||
| } | ||||
|   | ||||
| @@ -22,16 +22,12 @@ impl Header for SetCookie { | ||||
|  | ||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<SetCookie> { | ||||
|         let mut set_cookies = Vec::with_capacity(raw.len()); | ||||
|         for set_cookies_raw in raw.iter() { | ||||
|             match from_utf8(&set_cookies_raw[..]) { | ||||
|                 Ok(s) if !s.is_empty() => { | ||||
|                     match s.parse() { | ||||
|                         Ok(cookie) => set_cookies.push(cookie), | ||||
|                         Err(_) => () | ||||
|                     } | ||||
|                 }, | ||||
|                 _ => () | ||||
|             }; | ||||
|         for set_cookies_raw in raw { | ||||
|             if let Ok(s) = from_utf8(&set_cookies_raw[..]) { | ||||
|                 if let Ok(cookie) = s.parse() { | ||||
|                     set_cookies.push(cookie); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if !set_cookies.is_empty() { | ||||
|   | ||||
| @@ -252,10 +252,7 @@ impl<'a> Iterator for HeadersItems<'a> { | ||||
|     type Item = HeaderView<'a>; | ||||
|  | ||||
|     fn next(&mut self) -> Option<HeaderView<'a>> { | ||||
|         match self.inner.next() { | ||||
|             Some((k, v)) => Some(HeaderView(k, v)), | ||||
|             None => None | ||||
|         } | ||||
|         self.inner.next().map(|(k, v)| HeaderView(k, v)) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -9,10 +9,12 @@ pub fn from_one_raw_str<T: str::FromStr>(raw: &[Vec<u8>]) -> Option<T> { | ||||
|         return None; | ||||
|     } | ||||
|     // we JUST checked that raw.len() == 1, so raw[0] WILL exist. | ||||
|     match str::from_utf8(&raw[0][..]) { | ||||
|         Ok(s) => str::FromStr::from_str(s).ok(), | ||||
|         Err(_) => None | ||||
|     if let Ok(s) = str::from_utf8(&raw[0][..]) { | ||||
|         if s != "" { | ||||
|             return str::FromStr::from_str(s).ok(); | ||||
|         } | ||||
|     } | ||||
|     None | ||||
| } | ||||
|  | ||||
| /// Reads a comma-delimited raw header into a Vec. | ||||
|   | ||||
| @@ -46,12 +46,7 @@ impl FromStr for HttpDate { | ||||
|  | ||||
| impl Display for HttpDate { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         let tm = self.0; | ||||
|         let tm = match tm.tm_utcoff { | ||||
|             0 => tm, | ||||
|             _ => tm.to_utc(), | ||||
|         }; | ||||
|         fmt::Display::fmt(&tm.rfc822(), f) | ||||
|         fmt::Display::fmt(&self.0.to_utc().rfc822(), f) | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -300,7 +300,7 @@ impl<W: Write> Write for HttpWriter<W> { | ||||
|                 } | ||||
|             }, | ||||
|             EmptyWriter(..) => { | ||||
|                 if msg.len() != 0 { | ||||
|                 if !msg.is_empty() { | ||||
|                     error!("Cannot include a body with this kind of message"); | ||||
|                 } | ||||
|                 Ok(0) | ||||
| @@ -354,7 +354,7 @@ fn parse<R: Read, T: TryParse<Subject=I>, I>(rdr: &mut BufReader<R>) -> HttpResu | ||||
|             _partial => () | ||||
|         } | ||||
|         match try!(rdr.read_into_buf()) { | ||||
|             0 if rdr.get_buf().len() == 0 => { | ||||
|             0 if rdr.get_buf().is_empty() => { | ||||
|                 return Err(HttpIoError(io::Error::new( | ||||
|                     io::ErrorKind::ConnectionAborted, | ||||
|                     "Connection closed" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user