Skip to content

Commit

Permalink
refactor(lib): update unicase to 2.0
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Some headers used `UniCase`, but now use
  `unicase::Ascii`. Upgrade code to `Ascii::new(s)`.
  • Loading branch information
seanmonstar committed May 10, 2017
1 parent fed04df commit c81edd4
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tokio-core = "0.1.6"
tokio-proto = "0.1"
tokio-service = "0.1"
tokio-io = "0.1"
unicase = "1.0"
unicase = "2.0"
url = "1.0"

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions src/header/common/access_control_allow_credentials.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::{self, Display};
use std::str;
use unicase::UniCase;
use unicase;
use header::{Header, Raw};

/// `Access-Control-Allow-Credentials` header, part of
Expand Down Expand Up @@ -38,7 +38,7 @@ use header::{Header, Raw};
#[derive(Clone, PartialEq, Debug)]
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 {
fn header_name() -> &'static str {
Expand All @@ -56,7 +56,7 @@ impl Header for AccessControlAllowCredentials {
// None. No big deal.
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);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/header/common/access_control_allow_headers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use unicase::UniCase;
use unicase::Ascii;

header! {
/// `Access-Control-Allow-Headers` header, part of
Expand All @@ -24,11 +24,11 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, AccessControlAllowHeaders};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// AccessControlAllowHeaders(vec![UniCase("date".to_owned())])
/// AccessControlAllowHeaders(vec![Ascii::new("date".to_owned())])
/// );
/// # }
/// ```
Expand All @@ -39,18 +39,18 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, AccessControlAllowHeaders};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// AccessControlAllowHeaders(vec![
/// UniCase("accept-language".to_owned()),
/// UniCase("date".to_owned()),
/// Ascii::new("accept-language".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_header!(test1, vec![b"accept-language, date"]);
Expand Down
16 changes: 8 additions & 8 deletions src/header/common/access_control_expose_headers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use unicase::UniCase;
use unicase::Ascii;

header! {
/// `Access-Control-Expose-Headers` header, part of
Expand All @@ -23,13 +23,13 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, AccessControlExposeHeaders};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// AccessControlExposeHeaders(vec![
/// UniCase("etag".to_owned()),
/// UniCase("content-length".to_owned())
/// Ascii::new("etag".to_owned()),
/// Ascii::new("content-length".to_owned())
/// ])
/// );
/// # }
Expand All @@ -41,18 +41,18 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, AccessControlExposeHeaders};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// AccessControlExposeHeaders(vec![
/// UniCase("etag".to_owned()),
/// UniCase("content-length".to_owned())
/// Ascii::new("etag".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_header!(test1, vec![b"etag, content-length"]);
Expand Down
14 changes: 7 additions & 7 deletions src/header/common/access_control_request_headers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use unicase::UniCase;
use unicase::Ascii;

header! {
/// `Access-Control-Request-Headers` header, part of
Expand All @@ -24,11 +24,11 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, AccessControlRequestHeaders};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// AccessControlRequestHeaders(vec![UniCase("date".to_owned())])
/// AccessControlRequestHeaders(vec![Ascii::new("date".to_owned())])
/// );
/// # }
/// ```
Expand All @@ -39,18 +39,18 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, AccessControlRequestHeaders};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// AccessControlRequestHeaders(vec![
/// UniCase("accept-language".to_owned()),
/// UniCase("date".to_owned()),
/// Ascii::new("accept-language".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_header!(test1, vec![b"accept-language, date"]);
Expand Down
24 changes: 12 additions & 12 deletions src/header/common/connection.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::fmt::{self, Display};
use std::str::FromStr;
use unicase::UniCase;
use unicase::Ascii;

pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader};

const KEEP_ALIVE: UniCase<&'static str> = UniCase("keep-alive");
const CLOSE: UniCase<&'static str> = UniCase("close");
static KEEP_ALIVE: &'static str = "keep-alive";
static CLOSE: &'static str = "close";

/// Values that can be in the `Connection` header.
#[derive(Clone, PartialEq, Debug)]
Expand All @@ -22,18 +22,18 @@ pub enum ConnectionOption {
// 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
// types for).
ConnectionHeader(UniCase<String>),
ConnectionHeader(Ascii<String>),
}

impl FromStr for ConnectionOption {
type Err = ();
fn from_str(s: &str) -> Result<ConnectionOption, ()> {
if UniCase(s) == KEEP_ALIVE {
if Ascii::new(s) == KEEP_ALIVE {
Ok(KeepAlive)
} else if UniCase(s) == CLOSE {
} else if Ascii::new(s) == CLOSE {
Ok(Close)
} else {
Ok(ConnectionHeader(UniCase(s.to_owned())))
Ok(ConnectionHeader(Ascii::new(s.to_owned())))
}
}
}
Expand All @@ -43,7 +43,7 @@ impl Display for ConnectionOption {
f.write_str(match *self {
KeepAlive => "keep-alive",
Close => "close",
ConnectionHeader(UniCase(ref s)) => s.as_ref()
ConnectionHeader(ref s) => s.as_ref()
})
}
}
Expand Down Expand Up @@ -83,12 +83,12 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, Connection, ConnectionOption};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// Connection(vec![
/// ConnectionOption::ConnectionHeader(UniCase("upgrade".to_owned())),
/// ConnectionOption::ConnectionHeader(Ascii::new("upgrade".to_owned())),
/// ])
/// );
/// # }
Expand Down Expand Up @@ -124,7 +124,7 @@ bench_header!(header, Connection, { vec![b"authorization".to_vec()] });
mod tests {
use super::{Connection,ConnectionHeader};
use header::Header;
use unicase::UniCase;
use unicase::Ascii;

fn parse_option(header: Vec<u8>) -> Connection {
let val = header.into();
Expand All @@ -137,7 +137,7 @@ mod tests {
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(vec![ConnectionHeader(UniCase("upgrade".to_owned()))]),
assert_eq!(Connection(vec![ConnectionHeader(Ascii::new("upgrade".to_owned()))]),
parse_option(b"upgrade".to_vec()));
}
}
12 changes: 6 additions & 6 deletions src/header/common/content_disposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use language_tags::LanguageTag;
use std::fmt;
use unicase::UniCase;
use unicase;

use header::{Header, Raw, parsing};
use header::parsing::{parse_extended_value, http_percent_encode};
Expand Down Expand Up @@ -102,9 +102,9 @@ impl Header for ContentDisposition {
};

let mut cd = ContentDisposition {
disposition: if UniCase(&*disposition) == UniCase("inline") {
disposition: if unicase::eq_ascii(&*disposition, "inline") {
DispositionType::Inline
} else if UniCase(&*disposition) == UniCase("attachment") {
} else if unicase::eq_ascii(&*disposition, "attachment") {
DispositionType::Attachment
} else {
DispositionType::Ext(disposition.to_owned())
Expand All @@ -128,11 +128,11 @@ impl Header for ContentDisposition {
};

cd.parameters.push(
if UniCase(&*key) == UniCase("filename") {
if unicase::eq_ascii(&*key, "filename") {
DispositionParam::Filename(
Charset::Ext("UTF-8".to_owned()), None,
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));
DispositionParam::Filename(extended_value.charset, extended_value.language_tag, extended_value.value)
} else {
Expand Down Expand Up @@ -164,7 +164,7 @@ impl fmt::Display for ContentDisposition {
let mut use_simple_format: bool = false;
if opt_lang.is_none() {
if let Charset::Ext(ref ext) = *charset {
if UniCase(&**ext) == UniCase("utf-8") {
if unicase::eq_ascii(&**ext, "utf-8") {
use_simple_format = true;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/header/common/expect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;
use std::str;

use unicase::UniCase;
use unicase;

use header::{Header, Raw};

Expand All @@ -26,8 +26,6 @@ pub enum Expect {
Continue
}

const EXPECT_CONTINUE: UniCase<&'static str> = UniCase("100-continue");

impl Header for Expect {
fn header_name() -> &'static str {
static NAME: &'static str = "Expect";
Expand All @@ -44,7 +42,7 @@ impl Header for Expect {
// None. No big deal.
str::from_utf8_unchecked(line)
};
if UniCase(text) == EXPECT_CONTINUE {
if unicase::eq_ascii(text, "100-continue") {
Ok(Expect::Continue)
} else {
Err(::Error::Header)
Expand Down
6 changes: 3 additions & 3 deletions src/header/common/strict_transport_security.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;
use std::str::{self, FromStr};

use unicase::UniCase;
use unicase;

use header::{Header, Raw, parsing};

Expand Down Expand Up @@ -85,13 +85,13 @@ impl FromStr for StrictTransportSecurity {
fn from_str(s: &str) -> ::Result<StrictTransportSecurity> {
s.split(';')
.map(str::trim)
.map(|sub| if UniCase(sub) == UniCase("includeSubdomains") {
.map(|sub| if unicase::eq_ascii(sub, "includeSubdomains") {
Ok(Directive::IncludeSubdomains)
} else {
let mut sub = sub.splitn(2, '=');
match (sub.next(), sub.next()) {
(Some(left), Some(right))
if UniCase(left.trim()) == UniCase("max-age") => {
if unicase::eq_ascii(left.trim(), "max-age") => {
right
.trim()
.trim_matches('"')
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::{self, Display};
use std::str::FromStr;
use unicase::UniCase;
use unicase;

header! {
/// `Upgrade` header, defined in [RFC7230](http://tools.ietf.org/html/rfc7230#section-6.7)
Expand Down Expand Up @@ -99,7 +99,7 @@ impl FromStr for ProtocolName {
"TLS" => ProtocolName::Tls,
"h2c" => ProtocolName::H2c,
_ => {
if UniCase(s) == UniCase("websocket") {
if unicase::eq_ascii(s, "websocket") {
ProtocolName::WebSocket
} else {
ProtocolName::Unregistered(s.to_owned())
Expand Down
10 changes: 5 additions & 5 deletions src/header/common/vary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use unicase::UniCase;
use unicase::Ascii;

header! {
/// `Vary` header, defined in [RFC7231](https://tools.ietf.org/html/rfc7231#section-7.1.4)
Expand Down Expand Up @@ -34,18 +34,18 @@ header! {
/// // extern crate unicase;
///
/// use hyper::header::{Headers, Vary};
/// use unicase::UniCase;
/// use unicase::Ascii;
///
/// let mut headers = Headers::new();
/// headers.set(
/// Vary::Items(vec![
/// UniCase("accept-encoding".to_owned()),
/// UniCase("accept-language".to_owned()),
/// Ascii::new("accept-encoding".to_owned()),
/// Ascii::new("accept-language".to_owned()),
/// ])
/// );
/// # }
/// ```
(Vary, "Vary") => {Any / (UniCase<String>)+}
(Vary, "Vary") => {Any / (Ascii<String>)+}

test_vary {
test_header!(test1, vec![b"accept-encoding, accept-language"]);
Expand Down
Loading

0 comments on commit c81edd4

Please sign in to comment.