Struct web_socket::http::Http
source · pub struct Http<'a> {
pub schema: &'a [u8],
pub headers: HashMap<String, &'a [u8]>,
}Expand description
It represents an HTTP message with a schema and a header.
Example
let mut bytes = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n".as_bytes();
let header = web_socket::http::Http::parse(&mut bytes).unwrap();
assert_eq!(header.schema, "HTTP/1.1 101 Switching Protocols".as_bytes());
assert_eq!(header.get("upgrade"), Some("websocket".as_bytes()));
assert_eq!(
header.get("sec-websocket-accept"),
Some("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=".as_bytes())
);Fields§
§schema: &'a [u8]schema of the http message (e.g. HTTP/1.1 101 Switching Protocols)
headers: HashMap<String, &'a [u8]>key-value pairs of http headers
Implementations§
source§impl<'a> Http<'a>
impl<'a> Http<'a>
sourcepub fn is_ws_upgrade(&self) -> bool
pub fn is_ws_upgrade(&self) -> bool
Determine if the incoming HTTP request is an upgrade request to the WebSocket protocol.
sourcepub fn get_sec_ws_key(&self) -> Option<&[u8]>
pub fn get_sec_ws_key(&self) -> Option<&[u8]>
get http sec-websocket-key header value.