wist/adapters/mist
Wist adapter for the Mist web server.
This module implements the transport adapter bridging Mist’s WebSocket upgrade
logic and connection actor loops to Wist’s transport-neutral Handler API.
Use upgrade inside your Mist HTTP request handler to switch protocols and
run a stateful Wist handler.
Values
pub fn upgrade(
request: request.Request(mist.Connection),
handler: wist.Handler(state, inbound, outbound),
codec: wist.Codec(inbound, outbound),
) -> response.Response(mist.ResponseData)
Upgrades an incoming HTTP request to a WebSocket connection managed by Wist.
If the request is a valid WebSocket handshake request, it returns a 101 Switching Protocols response body configured to spawn Mist’s WebSocket handler process. If the request is malformed or invalid, a 400 Bad Request response is returned.
Parameters
request: The incoming HTTP request carrying the Mist transportConnection.handler: The statefulwist.Handlerdefining initial state and event transitions.codec: Awist.Codecspecifying how to encode and decode wire frames.
Guarantees
- Serialization: Connection events are processed strictly sequentially.
updateis never run concurrently. - FIFO Effects: Effects returned by
updateare executed in the exact order they are listed. - Safety: If frame decoding fails, the connection is closed immediately, and a
Failedevent is dispatched.
Limitations
- Outbound pings are supported via the
wist.Pingeffect, but clientPongframes are swallowed by Mist’s internal wrapper and will not be dispatched as events.
Example
import wist
import wist/adapters/mist as wist_mist
fn my_http_handler(req) {
case req.path {
"/ws" -> wist_mist.upgrade(req, my_ws_handler, wist.raw_codec())
_ -> response.new(200)
}
}