Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand All @@ -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],
Expand Down