pub struct WebSocket;Expand description
WebSocket protocol utilities.
Implementations§
Source§impl WebSocket
impl WebSocket
Sourcepub fn is_upgrade_request(request: &Request) -> bool
pub fn is_upgrade_request(request: &Request) -> bool
Returns true if request is a valid WebSocket upgrade request
(has Upgrade: websocket, Connection: upgrade, and Sec-WebSocket-Key).
Sourcepub fn handshake_response(request: &Request) -> Result<Response, String>
pub fn handshake_response(request: &Request) -> Result<Response, String>
Build the HTTP 101 Switching Protocols response for a WebSocket
opening handshake. Returns an error if Sec-WebSocket-Key is absent.
Write the raw bytes from Response::generate_response to the stream,
then transition to frame-level I/O with WebSocket::read_frame /
WebSocket::write_frame.
Sourcepub fn accept_key(client_key: &str) -> String
pub fn accept_key(client_key: &str) -> String
Compute the Sec-WebSocket-Accept value from the client’s
Sec-WebSocket-Key using SHA-1 and base64 as specified in RFC 6455.
Sourcepub fn read_frame(stream: &mut impl Read) -> Result<Frame, String>
pub fn read_frame(stream: &mut impl Read) -> Result<Frame, String>
Read one WebSocket frame from stream.
Handles client-to-server masking automatically. Returns an error if the stream closes unexpectedly or contains a protocol violation.
Sourcepub fn write_frame(stream: &mut impl Write, frame: Frame) -> Result<(), String>
pub fn write_frame(stream: &mut impl Write, frame: Frame) -> Result<(), String>
Write a WebSocket frame to stream (server→client, unmasked).
Sourcepub fn send_text(stream: &mut impl Write, text: &str) -> Result<(), String>
pub fn send_text(stream: &mut impl Write, text: &str) -> Result<(), String>
Convenience: send a text message.