pub fn read_http_header<'a>(
headers: impl Iterator<Item = (&'a str, &'a [u8])>,
) -> Result<Option<WebSocketContext>>
Expand description
Reads an http header and extracts websocket specific information from it.
ยงExamples
use embedded_websocket as ws;
let client_request = "GET /chat HTTP/1.1
Host: myserver.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: Z7OY1UwHOx/nkSz38kfPwg==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, advancedchat
Sec-WebSocket-Version: 13
";
let mut headers = [httparse::EMPTY_HEADER; 16];
let mut request = httparse::Request::new(&mut headers);
request.parse(client_request.as_bytes()).unwrap();
let headers = request.headers.iter().map(|f| (f.name, f.value));
let ws_context = ws::read_http_header(headers).unwrap().unwrap();
assert_eq!("Z7OY1UwHOx/nkSz38kfPwg==", ws_context.sec_websocket_key);
assert_eq!("chat", ws_context.sec_websocket_protocol_list.get(0).unwrap().as_str());
assert_eq!("advancedchat", ws_context.sec_websocket_protocol_list.get(1).unwrap().as_str());