Skip to content

Commit

Permalink
Merge pull request #270 from cyderize/case-insensitive
Browse files Browse the repository at this point in the history
fix(headers): make ConnectionHeader and search for websocket protocol unicase
  • Loading branch information
seanmonstar committed Jan 24, 2015
2 parents fc67a12 + e06e7d9 commit fb92a26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/header/common/connection.rs
Expand Up @@ -2,6 +2,7 @@ use header::{Header, HeaderFormat};
use std::fmt;
use std::str::FromStr;
use header::parsing::{from_comma_delimited, fmt_comma_delimited};
use unicase::UniCase;

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

Expand All @@ -26,15 +27,15 @@ 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(String),
ConnectionHeader(UniCase<String>),
}

impl FromStr for ConnectionOption {
fn from_str(s: &str) -> Option<ConnectionOption> {
match s {
"keep-alive" => Some(KeepAlive),
"close" => Some(Close),
s => Some(ConnectionHeader(s.to_string()))
s => Some(ConnectionHeader(UniCase(s.to_string())))
}
}
}
Expand All @@ -44,7 +45,7 @@ impl fmt::Display for ConnectionOption {
write!(fmt, "{}", match *self {
KeepAlive => "keep-alive",
Close => "close",
ConnectionHeader(ref s) => s.as_slice()
ConnectionHeader(UniCase(ref s)) => s.as_slice()
})
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/header/common/upgrade.rs
Expand Up @@ -2,6 +2,7 @@ use header::{Header, HeaderFormat};
use std::fmt;
use std::str::FromStr;
use header::parsing::{from_comma_delimited, fmt_comma_delimited};
use unicase::UniCase;

use self::Protocol::{WebSocket, ProtocolExt};

Expand All @@ -22,9 +23,11 @@ pub enum Protocol {

impl FromStr for Protocol {
fn from_str(s: &str) -> Option<Protocol> {
match s {
"websocket" => Some(WebSocket),
s => Some(ProtocolExt(s.to_string()))
if UniCase(s) == UniCase("websocket") {
Some(WebSocket)
}
else {
Some(ProtocolExt(s.to_string()))
}
}
}
Expand Down

0 comments on commit fb92a26

Please sign in to comment.