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