Skip to content

Commit

Permalink
fix(headers): case insensitive values for Connection header
Browse files Browse the repository at this point in the history
Closes #635
  • Loading branch information
mikedilger committed Aug 27, 2015
1 parent 44a4010 commit 341f8ea
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/header/common/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use unicase::UniCase;

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

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

/// Values that can be in the `Connection` header.
#[derive(Clone, PartialEq, Debug)]
pub enum ConnectionOption {
Expand All @@ -25,10 +28,12 @@ pub enum ConnectionOption {
impl FromStr for ConnectionOption {
type Err = ();
fn from_str(s: &str) -> Result<ConnectionOption, ()> {
match s {
"keep-alive" => Ok(KeepAlive),
"close" => Ok(Close),
s => Ok(ConnectionHeader(UniCase(s.to_owned())))
if UniCase(s) == KEEP_ALIVE {
Ok(KeepAlive)
} else if UniCase(s) == CLOSE {
Ok(Close)
} else {
Ok(ConnectionHeader(UniCase(s.to_owned())))
}
}
}
Expand Down Expand Up @@ -131,6 +136,7 @@ mod tests {
fn test_parse() {
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()))]),
parse_option(b"upgrade".to_vec()));
}
Expand Down

0 comments on commit 341f8ea

Please sign in to comment.