adapter
ModuleThe interface every server adapter implements, and the hooks it calls.
Contents
Type aliases
CloseHookCalled when a connection is closed, by either side.ConnectionIdThe id of one WebSocket connection, unique while it is open.MessageHookCalled with each message a connection sends.OpenHookCalled when a connection is established, with its handshake request.RequestAn HTTP request: the handshake of a WebSocket connection (to `Adapter::on_open`) or a plain request on the server's port (to `Adapter::on_request`).RequestHookCalled with each plain HTTP request and the response to fill.ResponseThe response an `Adapter::on_request` hook fills: `200 OK` with no headers and an empty body until the hook changes it.StartHookCalled once when the server starts listening.WorkerHookCalled with a worker id when a worker starts or stops.use utopia_websocket::Adapter;Rust
pub trait Adapter: Send + Sync + 'staticRust
pub type CloseHook = Arc<dyn Fn(ConnectionId) + Send + Sync>Called when a connection is closed, by either side.
Rust
pub type ConnectionId = i64The id of one WebSocket connection, unique while it is open.
Rust
pub type MessageHook = Arc<dyn Fn(ConnectionId, &[u8]) + Send + Sync>Called with each message a connection sends.
Rust
pub type OpenHook = Arc<dyn Fn(ConnectionId, &Request) + Send + Sync>Called when a connection is established, with its handshake request.
Rust
pub type Request = http::Request<Bytes>An HTTP request: the handshake of a WebSocket connection (to
Adapter::on_open) or a plain request on the server's port (to
Adapter::on_request).
Rust
pub type RequestHook = Arc<dyn Fn(&Request, &mut Response) + Send + Sync>Called with each plain HTTP request and the response to fill.
Rust
pub type Response = http::Response<Vec<u8>>The response an Adapter::on_request hook fills: 200 OK with no
headers and an empty body until the hook changes it.
Rust
pub type StartHook = Arc<dyn Fn() + Send + Sync>Called once when the server starts listening.
Rust
pub type WorkerHook = Arc<dyn Fn(i64) + Send + Sync>Called with a worker id when a worker starts or stops.