Merge pull request #636 from mikedilger/connection
fix(headers): case insensitive values for Connection header
This commit is contained in:
		| @@ -4,6 +4,9 @@ use unicase::UniCase; | |||||||
|  |  | ||||||
| pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader}; | 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. | /// Values that can be in the `Connection` header. | ||||||
| #[derive(Clone, PartialEq, Debug)] | #[derive(Clone, PartialEq, Debug)] | ||||||
| pub enum ConnectionOption { | pub enum ConnectionOption { | ||||||
| @@ -25,10 +28,12 @@ pub enum ConnectionOption { | |||||||
| 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, ()> { | ||||||
|         match s { |         if UniCase(s) == KEEP_ALIVE { | ||||||
|             "keep-alive" => Ok(KeepAlive), |             Ok(KeepAlive) | ||||||
|             "close" => Ok(Close), |         } else if UniCase(s) == CLOSE { | ||||||
|             s => Ok(ConnectionHeader(UniCase(s.to_owned()))) |             Ok(Close) | ||||||
|  |         } else { | ||||||
|  |             Ok(ConnectionHeader(UniCase(s.to_owned()))) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -131,6 +136,7 @@ mod tests { | |||||||
|     fn test_parse() { |     fn test_parse() { | ||||||
|         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(vec![ConnectionHeader(UniCase("upgrade".to_owned()))]), |         assert_eq!(Connection(vec![ConnectionHeader(UniCase("upgrade".to_owned()))]), | ||||||
|             parse_option(b"upgrade".to_vec())); |             parse_option(b"upgrade".to_vec())); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user