Skip to content

blackbull.middleware.websocket

blackbull.middleware.websocket

Handshake middleware — accepts the connection before the handler runs.

Predates the high-level :class:~blackbull.websocket.WebSocket object and exists to strip the accept/close boilerplate from raw-triplet handlers. It works with either handler form: it records the handshake on the connection, so a WebSocket object built downstream adopts that state instead of waiting for a websocket.connect that has already been consumed.

With the object form the middleware is largely redundant — await ws.accept() is the line it was removing — but combining them is supported rather than refused, because a route's middleware list and its handler signature are usually changed by different people at different times.