Merge pull request #270 from cyderize/case-insensitive
fix(headers): make ConnectionHeader and search for websocket protocol unicase
This commit is contained in:
@@ -2,6 +2,7 @@ use header::{Header, HeaderFormat};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use header::parsing::{from_comma_delimited, fmt_comma_delimited};
|
use header::parsing::{from_comma_delimited, fmt_comma_delimited};
|
||||||
|
use unicase::UniCase;
|
||||||
|
|
||||||
pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader};
|
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
|
// 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
|
// they are supposed to relate to other Header fields (which we have strong
|
||||||
// types for).
|
// types for).
|
||||||
ConnectionHeader(String),
|
ConnectionHeader(UniCase<String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for ConnectionOption {
|
impl FromStr for ConnectionOption {
|
||||||
@@ -34,7 +35,7 @@ impl FromStr for ConnectionOption {
|
|||||||
match s {
|
match s {
|
||||||
"keep-alive" => Some(KeepAlive),
|
"keep-alive" => Some(KeepAlive),
|
||||||
"close" => Some(Close),
|
"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 {
|
write!(fmt, "{}", match *self {
|
||||||
KeepAlive => "keep-alive",
|
KeepAlive => "keep-alive",
|
||||||
Close => "close",
|
Close => "close",
|
||||||
ConnectionHeader(ref s) => s.as_slice()
|
ConnectionHeader(UniCase(ref s)) => s.as_slice()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use header::{Header, HeaderFormat};
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use header::parsing::{from_comma_delimited, fmt_comma_delimited};
|
use header::parsing::{from_comma_delimited, fmt_comma_delimited};
|
||||||
|
use unicase::UniCase;
|
||||||
|
|
||||||
use self::Protocol::{WebSocket, ProtocolExt};
|
use self::Protocol::{WebSocket, ProtocolExt};
|
||||||
|
|
||||||
@@ -22,9 +23,11 @@ pub enum Protocol {
|
|||||||
|
|
||||||
impl FromStr for Protocol {
|
impl FromStr for Protocol {
|
||||||
fn from_str(s: &str) -> Option<Protocol> {
|
fn from_str(s: &str) -> Option<Protocol> {
|
||||||
match s {
|
if UniCase(s) == UniCase("websocket") {
|
||||||
"websocket" => Some(WebSocket),
|
Some(WebSocket)
|
||||||
s => Some(ProtocolExt(s.to_string()))
|
}
|
||||||
|
else {
|
||||||
|
Some(ProtocolExt(s.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user