diff --git a/src/http.rs b/src/http.rs index 408a3c5..6afd1ad 100644 --- a/src/http.rs +++ b/src/http.rs @@ -45,7 +45,7 @@ pub fn read_http_header<'a>( let mut sec_websocket_key = String::new(); for (name, value) in headers { - match name { + match_ascii_case_insensitive!{ name, "Upgrade" => is_websocket_request = str::from_utf8(value)? == "websocket", "Sec-WebSocket-Protocol" => { // extract a csv list of supported sub protocols @@ -58,11 +58,11 @@ pub fn read_http_header<'a>( .unwrap(); } } - } + }, "Sec-WebSocket-Key" => { sec_websocket_key = String::from(str::from_utf8(value)?); - } - &_ => { + }, + _ => { // ignore all other headers } } @@ -78,6 +78,14 @@ pub fn read_http_header<'a>( } } +macro_rules! match_ascii_case_insensitive { + ($m:expr, $($case:literal => $do:expr),+ , _ => $default:expr) => { + if false {} + $(else if $m.eq_ignore_ascii_case($case) { $do })+ + else {$default} + }; +} + pub fn read_server_connect_handshake_response( sec_websocket_key: &WebSocketKey, from: &[u8],