refactor(lib): update unicase to 2.0
BREAKING CHANGE: Some headers used `UniCase`, but now use `unicase::Ascii`. Upgrade code to `Ascii::new(s)`.
This commit is contained in:
		| @@ -32,7 +32,7 @@ tokio-core = "0.1.6" | |||||||
| tokio-proto = "0.1" | tokio-proto = "0.1" | ||||||
| tokio-service = "0.1" | tokio-service = "0.1" | ||||||
| tokio-io = "0.1" | tokio-io = "0.1" | ||||||
| unicase = "1.0" | unicase = "2.0" | ||||||
| url = "1.0" | url = "1.0" | ||||||
|  |  | ||||||
| [dev-dependencies] | [dev-dependencies] | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| use std::fmt::{self, Display}; | use std::fmt::{self, Display}; | ||||||
| use std::str; | use std::str; | ||||||
| use unicase::UniCase; | use unicase; | ||||||
| use header::{Header, Raw}; | use header::{Header, Raw}; | ||||||
|  |  | ||||||
| /// `Access-Control-Allow-Credentials` header, part of | /// `Access-Control-Allow-Credentials` header, part of | ||||||
| @@ -38,7 +38,7 @@ use header::{Header, Raw}; | |||||||
| #[derive(Clone, PartialEq, Debug)] | #[derive(Clone, PartialEq, Debug)] | ||||||
| pub struct AccessControlAllowCredentials; | pub struct AccessControlAllowCredentials; | ||||||
|  |  | ||||||
| const ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE: UniCase<&'static str> = UniCase("true"); | const ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE: &'static str = "true"; | ||||||
|  |  | ||||||
| impl Header for AccessControlAllowCredentials { | impl Header for AccessControlAllowCredentials { | ||||||
|     fn header_name() -> &'static str { |     fn header_name() -> &'static str { | ||||||
| @@ -56,7 +56,7 @@ impl Header for AccessControlAllowCredentials { | |||||||
|                 //    None. No big deal. |                 //    None. No big deal. | ||||||
|                 str::from_utf8_unchecked(line) |                 str::from_utf8_unchecked(line) | ||||||
|             }; |             }; | ||||||
|             if UniCase(text) == ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE { |             if unicase::eq_ascii(text, ACCESS_CONTROL_ALLOW_CREDENTIALS_TRUE) { | ||||||
|                 return Ok(AccessControlAllowCredentials); |                 return Ok(AccessControlAllowCredentials); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| use unicase::UniCase; | use unicase::Ascii; | ||||||
|  |  | ||||||
| header! { | header! { | ||||||
|     /// `Access-Control-Allow-Headers` header, part of |     /// `Access-Control-Allow-Headers` header, part of | ||||||
| @@ -24,11 +24,11 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, AccessControlAllowHeaders}; |     /// use hyper::header::{Headers, AccessControlAllowHeaders}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     AccessControlAllowHeaders(vec![UniCase("date".to_owned())]) |     ///     AccessControlAllowHeaders(vec![Ascii::new("date".to_owned())]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
| @@ -39,18 +39,18 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, AccessControlAllowHeaders}; |     /// use hyper::header::{Headers, AccessControlAllowHeaders}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     AccessControlAllowHeaders(vec![ |     ///     AccessControlAllowHeaders(vec![ | ||||||
|     ///         UniCase("accept-language".to_owned()), |     ///         Ascii::new("accept-language".to_owned()), | ||||||
|     ///         UniCase("date".to_owned()), |     ///         Ascii::new("date".to_owned()), | ||||||
|     ///     ]) |     ///     ]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
|     (AccessControlAllowHeaders, "Access-Control-Allow-Headers") => (UniCase<String>)* |     (AccessControlAllowHeaders, "Access-Control-Allow-Headers") => (Ascii<String>)* | ||||||
|  |  | ||||||
|     test_access_control_allow_headers { |     test_access_control_allow_headers { | ||||||
|         test_header!(test1, vec![b"accept-language, date"]); |         test_header!(test1, vec![b"accept-language, date"]); | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| use unicase::UniCase; | use unicase::Ascii; | ||||||
|  |  | ||||||
| header! { | header! { | ||||||
|     /// `Access-Control-Expose-Headers` header, part of |     /// `Access-Control-Expose-Headers` header, part of | ||||||
| @@ -23,13 +23,13 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, AccessControlExposeHeaders}; |     /// use hyper::header::{Headers, AccessControlExposeHeaders}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     AccessControlExposeHeaders(vec![ |     ///     AccessControlExposeHeaders(vec![ | ||||||
|     ///         UniCase("etag".to_owned()), |     ///         Ascii::new("etag".to_owned()), | ||||||
|     ///         UniCase("content-length".to_owned()) |     ///         Ascii::new("content-length".to_owned()) | ||||||
|     ///     ]) |     ///     ]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
| @@ -41,18 +41,18 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, AccessControlExposeHeaders}; |     /// use hyper::header::{Headers, AccessControlExposeHeaders}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     AccessControlExposeHeaders(vec![ |     ///     AccessControlExposeHeaders(vec![ | ||||||
|     ///         UniCase("etag".to_owned()), |     ///         Ascii::new("etag".to_owned()), | ||||||
|     ///         UniCase("content-length".to_owned()) |     ///         Ascii::new("content-length".to_owned()) | ||||||
|     ///     ]) |     ///     ]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
|     (AccessControlExposeHeaders, "Access-Control-Expose-Headers") => (UniCase<String>)* |     (AccessControlExposeHeaders, "Access-Control-Expose-Headers") => (Ascii<String>)* | ||||||
|  |  | ||||||
|     test_access_control_expose_headers { |     test_access_control_expose_headers { | ||||||
|         test_header!(test1, vec![b"etag, content-length"]); |         test_header!(test1, vec![b"etag, content-length"]); | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| use unicase::UniCase; | use unicase::Ascii; | ||||||
|  |  | ||||||
| header! { | header! { | ||||||
|     /// `Access-Control-Request-Headers` header, part of |     /// `Access-Control-Request-Headers` header, part of | ||||||
| @@ -24,11 +24,11 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, AccessControlRequestHeaders}; |     /// use hyper::header::{Headers, AccessControlRequestHeaders}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     AccessControlRequestHeaders(vec![UniCase("date".to_owned())]) |     ///     AccessControlRequestHeaders(vec![Ascii::new("date".to_owned())]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
| @@ -39,18 +39,18 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, AccessControlRequestHeaders}; |     /// use hyper::header::{Headers, AccessControlRequestHeaders}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     AccessControlRequestHeaders(vec![ |     ///     AccessControlRequestHeaders(vec![ | ||||||
|     ///         UniCase("accept-language".to_owned()), |     ///         Ascii::new("accept-language".to_owned()), | ||||||
|     ///         UniCase("date".to_owned()), |     ///         Ascii::new("date".to_owned()), | ||||||
|     ///     ]) |     ///     ]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
|     (AccessControlRequestHeaders, "Access-Control-Request-Headers") => (UniCase<String>)* |     (AccessControlRequestHeaders, "Access-Control-Request-Headers") => (Ascii<String>)* | ||||||
|  |  | ||||||
|     test_access_control_request_headers { |     test_access_control_request_headers { | ||||||
|         test_header!(test1, vec![b"accept-language, date"]); |         test_header!(test1, vec![b"accept-language, date"]); | ||||||
|   | |||||||
| @@ -1,11 +1,11 @@ | |||||||
| use std::fmt::{self, Display}; | use std::fmt::{self, Display}; | ||||||
| use std::str::FromStr; | use std::str::FromStr; | ||||||
| use unicase::UniCase; | use unicase::Ascii; | ||||||
|  |  | ||||||
| pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader}; | pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader}; | ||||||
|  |  | ||||||
| const KEEP_ALIVE: UniCase<&'static str> = UniCase("keep-alive"); | static KEEP_ALIVE: &'static str = "keep-alive"; | ||||||
| const CLOSE: UniCase<&'static str> = UniCase("close"); | static CLOSE: &'static str = "close"; | ||||||
|  |  | ||||||
| /// Values that can be in the `Connection` header. | /// Values that can be in the `Connection` header. | ||||||
| #[derive(Clone, PartialEq, Debug)] | #[derive(Clone, PartialEq, Debug)] | ||||||
| @@ -22,18 +22,18 @@ pub enum ConnectionOption { | |||||||
|     // TODO: it would be nice if these "Strings" could be stronger types, since |     // TODO: it would be nice if these "Strings" could be stronger types, since | ||||||
|     // they are supposed to relate to other Header fields (which we have strong |     // they are supposed to relate to other Header fields (which we have strong | ||||||
|     // types for). |     // types for). | ||||||
|     ConnectionHeader(UniCase<String>), |     ConnectionHeader(Ascii<String>), | ||||||
| } | } | ||||||
|  |  | ||||||
| impl FromStr for ConnectionOption { | impl FromStr for ConnectionOption { | ||||||
|     type Err = (); |     type Err = (); | ||||||
|     fn from_str(s: &str) -> Result<ConnectionOption, ()> { |     fn from_str(s: &str) -> Result<ConnectionOption, ()> { | ||||||
|         if UniCase(s) == KEEP_ALIVE { |         if Ascii::new(s) == KEEP_ALIVE { | ||||||
|             Ok(KeepAlive) |             Ok(KeepAlive) | ||||||
|         } else if UniCase(s) == CLOSE { |         } else if Ascii::new(s) == CLOSE { | ||||||
|             Ok(Close) |             Ok(Close) | ||||||
|         } else { |         } else { | ||||||
|             Ok(ConnectionHeader(UniCase(s.to_owned()))) |             Ok(ConnectionHeader(Ascii::new(s.to_owned()))) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -43,7 +43,7 @@ impl Display for ConnectionOption { | |||||||
|         f.write_str(match *self { |         f.write_str(match *self { | ||||||
|             KeepAlive => "keep-alive", |             KeepAlive => "keep-alive", | ||||||
|             Close => "close", |             Close => "close", | ||||||
|             ConnectionHeader(UniCase(ref s)) => s.as_ref() |             ConnectionHeader(ref s) => s.as_ref() | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -83,12 +83,12 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, Connection, ConnectionOption}; |     /// use hyper::header::{Headers, Connection, ConnectionOption}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     Connection(vec![ |     ///     Connection(vec![ | ||||||
|     ///         ConnectionOption::ConnectionHeader(UniCase("upgrade".to_owned())), |     ///         ConnectionOption::ConnectionHeader(Ascii::new("upgrade".to_owned())), | ||||||
|     ///     ]) |     ///     ]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
| @@ -124,7 +124,7 @@ bench_header!(header, Connection, { vec![b"authorization".to_vec()] }); | |||||||
| mod tests { | mod tests { | ||||||
|     use super::{Connection,ConnectionHeader}; |     use super::{Connection,ConnectionHeader}; | ||||||
|     use header::Header; |     use header::Header; | ||||||
|     use unicase::UniCase; |     use unicase::Ascii; | ||||||
|  |  | ||||||
|     fn parse_option(header: Vec<u8>) -> Connection { |     fn parse_option(header: Vec<u8>) -> Connection { | ||||||
|         let val = header.into(); |         let val = header.into(); | ||||||
| @@ -137,7 +137,7 @@ mod tests { | |||||||
|         assert_eq!(Connection::close(),parse_option(b"close".to_vec())); |         assert_eq!(Connection::close(),parse_option(b"close".to_vec())); | ||||||
|         assert_eq!(Connection::keep_alive(),parse_option(b"keep-alive".to_vec())); |         assert_eq!(Connection::keep_alive(),parse_option(b"keep-alive".to_vec())); | ||||||
|         assert_eq!(Connection::keep_alive(),parse_option(b"Keep-Alive".to_vec())); |         assert_eq!(Connection::keep_alive(),parse_option(b"Keep-Alive".to_vec())); | ||||||
|         assert_eq!(Connection(vec![ConnectionHeader(UniCase("upgrade".to_owned()))]), |         assert_eq!(Connection(vec![ConnectionHeader(Ascii::new("upgrade".to_owned()))]), | ||||||
|             parse_option(b"upgrade".to_vec())); |             parse_option(b"upgrade".to_vec())); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ | |||||||
|  |  | ||||||
| use language_tags::LanguageTag; | use language_tags::LanguageTag; | ||||||
| use std::fmt; | use std::fmt; | ||||||
| use unicase::UniCase; | use unicase; | ||||||
|  |  | ||||||
| use header::{Header, Raw, parsing}; | use header::{Header, Raw, parsing}; | ||||||
| use header::parsing::{parse_extended_value, http_percent_encode}; | use header::parsing::{parse_extended_value, http_percent_encode}; | ||||||
| @@ -102,9 +102,9 @@ impl Header for ContentDisposition { | |||||||
|             }; |             }; | ||||||
|  |  | ||||||
|             let mut cd = ContentDisposition { |             let mut cd = ContentDisposition { | ||||||
|                 disposition: if UniCase(&*disposition) == UniCase("inline") { |                 disposition: if unicase::eq_ascii(&*disposition, "inline") { | ||||||
|                     DispositionType::Inline |                     DispositionType::Inline | ||||||
|                 } else if UniCase(&*disposition) == UniCase("attachment") { |                 } else if unicase::eq_ascii(&*disposition, "attachment") { | ||||||
|                     DispositionType::Attachment |                     DispositionType::Attachment | ||||||
|                 } else { |                 } else { | ||||||
|                     DispositionType::Ext(disposition.to_owned()) |                     DispositionType::Ext(disposition.to_owned()) | ||||||
| @@ -128,11 +128,11 @@ impl Header for ContentDisposition { | |||||||
|                 }; |                 }; | ||||||
|  |  | ||||||
|                 cd.parameters.push( |                 cd.parameters.push( | ||||||
|                     if UniCase(&*key) == UniCase("filename") { |                     if unicase::eq_ascii(&*key, "filename") { | ||||||
|                         DispositionParam::Filename( |                         DispositionParam::Filename( | ||||||
|                             Charset::Ext("UTF-8".to_owned()), None, |                             Charset::Ext("UTF-8".to_owned()), None, | ||||||
|                             val.trim_matches('"').as_bytes().to_owned()) |                             val.trim_matches('"').as_bytes().to_owned()) | ||||||
|                     } else if UniCase(&*key) == UniCase("filename*") { |                     } else if unicase::eq_ascii(&*key, "filename*") { | ||||||
|                         let extended_value = try!(parse_extended_value(val)); |                         let extended_value = try!(parse_extended_value(val)); | ||||||
|                         DispositionParam::Filename(extended_value.charset, extended_value.language_tag, extended_value.value) |                         DispositionParam::Filename(extended_value.charset, extended_value.language_tag, extended_value.value) | ||||||
|                     } else { |                     } else { | ||||||
| @@ -164,7 +164,7 @@ impl fmt::Display for ContentDisposition { | |||||||
|                     let mut use_simple_format: bool = false; |                     let mut use_simple_format: bool = false; | ||||||
|                     if opt_lang.is_none() { |                     if opt_lang.is_none() { | ||||||
|                         if let Charset::Ext(ref ext) = *charset { |                         if let Charset::Ext(ref ext) = *charset { | ||||||
|                             if UniCase(&**ext) == UniCase("utf-8") { |                             if unicase::eq_ascii(&**ext, "utf-8") { | ||||||
|                                 use_simple_format = true; |                                 use_simple_format = true; | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| use std::fmt; | use std::fmt; | ||||||
| use std::str; | use std::str; | ||||||
|  |  | ||||||
| use unicase::UniCase; | use unicase; | ||||||
|  |  | ||||||
| use header::{Header, Raw}; | use header::{Header, Raw}; | ||||||
|  |  | ||||||
| @@ -26,8 +26,6 @@ pub enum Expect { | |||||||
|     Continue |     Continue | ||||||
| } | } | ||||||
|  |  | ||||||
| const EXPECT_CONTINUE: UniCase<&'static str> = UniCase("100-continue"); |  | ||||||
|  |  | ||||||
| impl Header for Expect { | impl Header for Expect { | ||||||
|     fn header_name() -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         static NAME: &'static str = "Expect"; |         static NAME: &'static str = "Expect"; | ||||||
| @@ -44,7 +42,7 @@ impl Header for Expect { | |||||||
|                 //    None. No big deal. |                 //    None. No big deal. | ||||||
|                 str::from_utf8_unchecked(line) |                 str::from_utf8_unchecked(line) | ||||||
|             }; |             }; | ||||||
|             if UniCase(text) == EXPECT_CONTINUE { |             if unicase::eq_ascii(text, "100-continue") { | ||||||
|                 Ok(Expect::Continue) |                 Ok(Expect::Continue) | ||||||
|             } else { |             } else { | ||||||
|                 Err(::Error::Header) |                 Err(::Error::Header) | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| use std::fmt; | use std::fmt; | ||||||
| use std::str::{self, FromStr}; | use std::str::{self, FromStr}; | ||||||
|  |  | ||||||
| use unicase::UniCase; | use unicase; | ||||||
|  |  | ||||||
| use header::{Header, Raw, parsing}; | use header::{Header, Raw, parsing}; | ||||||
|  |  | ||||||
| @@ -85,13 +85,13 @@ impl FromStr for StrictTransportSecurity { | |||||||
|     fn from_str(s: &str) -> ::Result<StrictTransportSecurity> { |     fn from_str(s: &str) -> ::Result<StrictTransportSecurity> { | ||||||
|         s.split(';') |         s.split(';') | ||||||
|             .map(str::trim) |             .map(str::trim) | ||||||
|             .map(|sub| if UniCase(sub) == UniCase("includeSubdomains") { |             .map(|sub| if unicase::eq_ascii(sub, "includeSubdomains") { | ||||||
|                 Ok(Directive::IncludeSubdomains) |                 Ok(Directive::IncludeSubdomains) | ||||||
|             } else { |             } else { | ||||||
|                 let mut sub = sub.splitn(2, '='); |                 let mut sub = sub.splitn(2, '='); | ||||||
|                 match (sub.next(), sub.next()) { |                 match (sub.next(), sub.next()) { | ||||||
|                     (Some(left), Some(right)) |                     (Some(left), Some(right)) | ||||||
|                     if UniCase(left.trim()) == UniCase("max-age") => { |                     if unicase::eq_ascii(left.trim(), "max-age") => { | ||||||
|                         right |                         right | ||||||
|                             .trim() |                             .trim() | ||||||
|                             .trim_matches('"') |                             .trim_matches('"') | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| use std::fmt::{self, Display}; | use std::fmt::{self, Display}; | ||||||
| use std::str::FromStr; | use std::str::FromStr; | ||||||
| use unicase::UniCase; | use unicase; | ||||||
|  |  | ||||||
| header! { | header! { | ||||||
|     /// `Upgrade` header, defined in [RFC7230](http://tools.ietf.org/html/rfc7230#section-6.7) |     /// `Upgrade` header, defined in [RFC7230](http://tools.ietf.org/html/rfc7230#section-6.7) | ||||||
| @@ -99,7 +99,7 @@ impl FromStr for ProtocolName { | |||||||
|             "TLS" => ProtocolName::Tls, |             "TLS" => ProtocolName::Tls, | ||||||
|             "h2c" => ProtocolName::H2c, |             "h2c" => ProtocolName::H2c, | ||||||
|             _ => { |             _ => { | ||||||
|                 if UniCase(s) == UniCase("websocket") { |                 if unicase::eq_ascii(s, "websocket") { | ||||||
|                     ProtocolName::WebSocket |                     ProtocolName::WebSocket | ||||||
|                 } else { |                 } else { | ||||||
|                     ProtocolName::Unregistered(s.to_owned()) |                     ProtocolName::Unregistered(s.to_owned()) | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| use unicase::UniCase; | use unicase::Ascii; | ||||||
|  |  | ||||||
| header! { | header! { | ||||||
|     /// `Vary` header, defined in [RFC7231](https://tools.ietf.org/html/rfc7231#section-7.1.4) |     /// `Vary` header, defined in [RFC7231](https://tools.ietf.org/html/rfc7231#section-7.1.4) | ||||||
| @@ -34,18 +34,18 @@ header! { | |||||||
|     /// // extern crate unicase; |     /// // extern crate unicase; | ||||||
|     /// |     /// | ||||||
|     /// use hyper::header::{Headers, Vary}; |     /// use hyper::header::{Headers, Vary}; | ||||||
|     /// use unicase::UniCase; |     /// use unicase::Ascii; | ||||||
|     /// |     /// | ||||||
|     /// let mut headers = Headers::new(); |     /// let mut headers = Headers::new(); | ||||||
|     /// headers.set( |     /// headers.set( | ||||||
|     ///     Vary::Items(vec![ |     ///     Vary::Items(vec![ | ||||||
|     ///         UniCase("accept-encoding".to_owned()), |     ///         Ascii::new("accept-encoding".to_owned()), | ||||||
|     ///         UniCase("accept-language".to_owned()), |     ///         Ascii::new("accept-language".to_owned()), | ||||||
|     ///     ]) |     ///     ]) | ||||||
|     /// ); |     /// ); | ||||||
|     /// # } |     /// # } | ||||||
|     /// ``` |     /// ``` | ||||||
|     (Vary, "Vary") => {Any / (UniCase<String>)+} |     (Vary, "Vary") => {Any / (Ascii<String>)+} | ||||||
|  |  | ||||||
|     test_vary { |     test_vary { | ||||||
|         test_header!(test1, vec![b"accept-encoding, accept-language"]); |         test_header!(test1, vec![b"accept-encoding, accept-language"]); | ||||||
|   | |||||||
| @@ -80,7 +80,7 @@ use std::borrow::{Cow, ToOwned}; | |||||||
| use std::iter::{FromIterator, IntoIterator}; | use std::iter::{FromIterator, IntoIterator}; | ||||||
| use std::{mem, fmt}; | use std::{mem, fmt}; | ||||||
|  |  | ||||||
| use unicase::UniCase; | use unicase::Ascii; | ||||||
|  |  | ||||||
| use self::internals::{Item, VecMap, Entry}; | use self::internals::{Item, VecMap, Entry}; | ||||||
| use self::sealed::{GetType, HeaderClone}; | use self::sealed::{GetType, HeaderClone}; | ||||||
| @@ -329,7 +329,7 @@ macro_rules! literals { | |||||||
|             match s.len() { |             match s.len() { | ||||||
|                 $($len => { |                 $($len => { | ||||||
|                     $( |                     $( | ||||||
|                     if UniCase(<$header>::header_name()) == s { |                     if Ascii::new(<$header>::header_name()) == Ascii::new(s) { | ||||||
|                         return Cow::Borrowed(<$header>::header_name()); |                         return Cow::Borrowed(<$header>::header_name()); | ||||||
|                     } |                     } | ||||||
|                     )+ |                     )+ | ||||||
| @@ -390,19 +390,19 @@ impl Headers { | |||||||
|     /// The field is determined by the type of the value being set. |     /// The field is determined by the type of the value being set. | ||||||
|     pub fn set<H: Header>(&mut self, value: H) { |     pub fn set<H: Header>(&mut self, value: H) { | ||||||
|         trace!("Headers.set( {:?}, {:?} )", header_name::<H>(), HeaderValueString(&value)); |         trace!("Headers.set( {:?}, {:?} )", header_name::<H>(), HeaderValueString(&value)); | ||||||
|         self.data.insert(HeaderName(UniCase(Cow::Borrowed(header_name::<H>()))), |         self.data.insert(HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>()))), | ||||||
|                          Item::new_typed(Box::new(value))); |                          Item::new_typed(Box::new(value))); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Get a reference to the header field's value, if it exists. |     /// Get a reference to the header field's value, if it exists. | ||||||
|     pub fn get<H: Header>(&self) -> Option<&H> { |     pub fn get<H: Header>(&self) -> Option<&H> { | ||||||
|         self.data.get(&HeaderName(UniCase(Cow::Borrowed(header_name::<H>())))) |         self.data.get(&HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>())))) | ||||||
|         .and_then(Item::typed::<H>) |         .and_then(Item::typed::<H>) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Get a mutable reference to the header field's value, if it exists. |     /// Get a mutable reference to the header field's value, if it exists. | ||||||
|     pub fn get_mut<H: Header>(&mut self) -> Option<&mut H> { |     pub fn get_mut<H: Header>(&mut self) -> Option<&mut H> { | ||||||
|         self.data.get_mut(&HeaderName(UniCase(Cow::Borrowed(header_name::<H>())))) |         self.data.get_mut(&HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>())))) | ||||||
|         .and_then(Item::typed_mut::<H>) |         .and_then(Item::typed_mut::<H>) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -418,7 +418,7 @@ impl Headers { | |||||||
|     /// assert!(headers.has::<ContentType>()); |     /// assert!(headers.has::<ContentType>()); | ||||||
|     /// ``` |     /// ``` | ||||||
|     pub fn has<H: Header>(&self) -> bool { |     pub fn has<H: Header>(&self) -> bool { | ||||||
|         self.data.contains_key(&HeaderName(UniCase(Cow::Borrowed(header_name::<H>())))) |         self.data.contains_key(&HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>())))) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Removes a header from the map, if one existed. |     /// Removes a header from the map, if one existed. | ||||||
| @@ -428,7 +428,7 @@ impl Headers { | |||||||
|     /// know whether a header exists, rather rely on `has`. |     /// know whether a header exists, rather rely on `has`. | ||||||
|     pub fn remove<H: Header>(&mut self) -> Option<H> { |     pub fn remove<H: Header>(&mut self) -> Option<H> { | ||||||
|         trace!("Headers.remove( {:?} )", header_name::<H>()); |         trace!("Headers.remove( {:?} )", header_name::<H>()); | ||||||
|         self.data.remove(&HeaderName(UniCase(Cow::Borrowed(header_name::<H>())))) |         self.data.remove(&HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>())))) | ||||||
|             .and_then(Item::into_typed::<H>) |             .and_then(Item::into_typed::<H>) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -484,7 +484,7 @@ impl Headers { | |||||||
|         let name = name.into(); |         let name = name.into(); | ||||||
|         let value = value.into(); |         let value = value.into(); | ||||||
|         trace!("Headers.set_raw( {:?}, {:?} )", name, value); |         trace!("Headers.set_raw( {:?}, {:?} )", name, value); | ||||||
|         self.data.insert(HeaderName(UniCase(name)), Item::new_raw(value)); |         self.data.insert(HeaderName(Ascii::new(name)), Item::new_raw(value)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Append a value to raw value of this header. |     /// Append a value to raw value of this header. | ||||||
| @@ -506,7 +506,7 @@ impl Headers { | |||||||
|         let name = name.into(); |         let name = name.into(); | ||||||
|         let value = value.into(); |         let value = value.into(); | ||||||
|         trace!("Headers.append_raw( {:?}, {:?} )", name, value); |         trace!("Headers.append_raw( {:?}, {:?} )", name, value); | ||||||
|         let name = HeaderName(UniCase(name)); |         let name = HeaderName(Ascii::new(name)); | ||||||
|         if let Some(item) = self.data.get_mut(&name) { |         if let Some(item) = self.data.get_mut(&name) { | ||||||
|             item.raw_mut().push(value); |             item.raw_mut().push(value); | ||||||
|             return; |             return; | ||||||
| @@ -520,7 +520,6 @@ impl Headers { | |||||||
|         self.data.remove(name); |         self.data.remove(name); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| impl PartialEq for Headers { | impl PartialEq for Headers { | ||||||
| @@ -577,7 +576,7 @@ impl<'a> HeaderView<'a> { | |||||||
|     /// Check if a HeaderView is a certain Header. |     /// Check if a HeaderView is a certain Header. | ||||||
|     #[inline] |     #[inline] | ||||||
|     pub fn is<H: Header>(&self) -> bool { |     pub fn is<H: Header>(&self) -> bool { | ||||||
|         HeaderName(UniCase(Cow::Borrowed(header_name::<H>()))) == *self.0 |         HeaderName(Ascii::new(Cow::Borrowed(header_name::<H>()))) == *self.0 | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Get the Header name as a slice. |     /// Get the Header name as a slice. | ||||||
| @@ -633,7 +632,7 @@ impl<'a> Extend<HeaderView<'a>> for Headers { | |||||||
| impl<'a> Extend<(&'a str, Bytes)> for Headers { | impl<'a> Extend<(&'a str, Bytes)> for Headers { | ||||||
|     fn extend<I: IntoIterator<Item=(&'a str, Bytes)>>(&mut self, iter: I) { |     fn extend<I: IntoIterator<Item=(&'a str, Bytes)>>(&mut self, iter: I) { | ||||||
|         for (name, value) in iter { |         for (name, value) in iter { | ||||||
|             let name = HeaderName(UniCase(maybe_literal(name))); |             let name = HeaderName(Ascii::new(maybe_literal(name))); | ||||||
|             //let trim = header.value.iter().rev().take_while(|&&x| x == b' ').count(); |             //let trim = header.value.iter().rev().take_while(|&&x| x == b' ').count(); | ||||||
|  |  | ||||||
|             match self.data.entry(name) { |             match self.data.entry(name) { | ||||||
| @@ -657,7 +656,7 @@ impl<'a> FromIterator<HeaderView<'a>> for Headers { | |||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Clone, Debug)] | #[derive(Clone, Debug)] | ||||||
| struct HeaderName(UniCase<Cow<'static, str>>); | struct HeaderName(Ascii<Cow<'static, str>>); | ||||||
|  |  | ||||||
| impl fmt::Display for HeaderName { | impl fmt::Display for HeaderName { | ||||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||||
| @@ -667,7 +666,7 @@ impl fmt::Display for HeaderName { | |||||||
|  |  | ||||||
| impl AsRef<str> for HeaderName { | impl AsRef<str> for HeaderName { | ||||||
|     fn as_ref(&self) -> &str { |     fn as_ref(&self) -> &str { | ||||||
|         ((self.0).0).as_ref() |         self.0.as_ref() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user