From 65c7018046eb556085ca47a28c980ec901980643 Mon Sep 17 00:00:00 2001 From: Jason N Date: Sat, 24 Jan 2015 16:08:09 +1100 Subject: [PATCH 1/2] fix(headers): make Protocol search websocket unicase RFC6455 requires the Upgrade Protocol to search case-insensitively for "websocket" Other protocol values may be case-sensitive, however, so ProtocolExt is still case-sensitive --- src/header/common/upgrade.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/header/common/upgrade.rs b/src/header/common/upgrade.rs index b3f03f83..6e304a70 100644 --- a/src/header/common/upgrade.rs +++ b/src/header/common/upgrade.rs @@ -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}; @@ -22,9 +23,11 @@ pub enum Protocol { impl FromStr for Protocol { fn from_str(s: &str) -> Option { - match s { - "websocket" => Some(WebSocket), - s => Some(ProtocolExt(s.to_string())) + if UniCase(s) == UniCase("websocket") { + Some(WebSocket) + } + else { + Some(ProtocolExt(s.to_string())) } } } From e06e7d9a7ece9588b673b06df6aec4663595df30 Mon Sep 17 00:00:00 2001 From: Jason N Date: Sat, 24 Jan 2015 16:09:20 +1100 Subject: [PATCH 2/2] fix(headers): make ConnectionHeader unicase Make ConnectionHeader case-insensitive since HTTP headers are case-insensitive --- src/header/common/connection.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/header/common/connection.rs b/src/header/common/connection.rs index 5820c88d..a4735f93 100644 --- a/src/header/common/connection.rs +++ b/src/header/common/connection.rs @@ -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}; @@ -26,7 +27,7 @@ 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), } impl FromStr for ConnectionOption { @@ -34,7 +35,7 @@ impl FromStr for ConnectionOption { match s { "keep-alive" => Some(KeepAlive), "close" => Some(Close), - s => Some(ConnectionHeader(s.to_string())) + s => Some(ConnectionHeader(UniCase(s.to_string()))) } } } @@ -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() }) } }