std::http::websocket¶
Status: experimental
RFC 6455 WebSocket support. Server-side accept + send_text / send_binary / ping / pong / close.
API details and source¶
The implementation source contains the complete declarations and implementation notes. The table below lists canonical Gossamer call signatures; every item name links directly to its implementation file.
| Item | Canonical signature or declaration | Description |
|---|---|---|
Error |
type Error |
Io / Protocol / BadHandshake. |
Message |
type Message |
Text / Binary / Ping / Pong / Close. |
WebSocket |
type WebSocket |
Accepted WebSocket connection (Rust-side framing). |
accept |
fn accept(request: http::Request) -> Result<http::websocket::Conn, errors::Error> |
Upgrade an incoming Request to a WebSocket (Rust-side). |
accept_key |
fn accept_key(key: String) -> String |
Compute RFC 6455 Sec-WebSocket-Accept from a client nonce. Available in interp + compiled. |
close |
fn close(conn: http::websocket::Conn) -> Result<(), errors::Error> |
close(ws) -> Result<(), Error>: send a close frame and release the handle. |
connect |
fn connect(url: String) -> Result<http::websocket::Conn, errors::Error> |
connect(url) -> Result |
is_websocket_upgrade |
fn is_websocket_upgrade(request: http::Request) -> bool |
Test whether an incoming Request carries a WebSocket upgrade handshake. Interp tier. |
recv |
fn recv(conn: http::websocket::Conn) -> Result<http::websocket::Message, errors::Error> |
recv(ws) -> Result |
send_binary |
fn send_binary(conn: http::websocket::Conn, data: Vec<u8>) -> Result<(), errors::Error> |
send_binary(ws, data) -> Result<(), Error>: send one binary frame. |
send_text |
fn send_text(conn: http::websocket::Conn, text: String) -> Result<(), errors::Error> |
send_text(ws, s) -> Result<(), Error>: send one text frame. |
serve |
fn serve(addr: String, handler: Fn(http::websocket::Conn) -> ()) -> Result<(), errors::Error> |
serve(addr, handler) -> Result<(), Error>: bind, upgrade each connection, dispatch the handler's handle(&self, ws) per connection. |