Websockets

WebSockets are supported by slimHTTP, but enabled by a plugin.
You’ll need to install slimWS one way or another.
After that, simply plug in the upgrader to slimHTTP:
import slimHTTP
import slimWS

http = slimHTTP.host(slimHTTP.HTTP)
websocket = spiderWeb.WebSocket()

@http.on_upgrade
def upgrade(request):
    new_identity = websocket.WS_CLIENT_IDENTITY(request)
    new_identity.upgrade(request) # Sends Upgrade request to client
    return new_identity

http.run()

Note

slimWS has a rudimentary API support, which can be viewed on the slimWS documentation.

The following example will catch any Connection: upgrade request,
and then proceed to in-memory replace the HTTP_CLIENT_IDENTITY with a slimWS.WS_CLIENT_IDENTITY.

Identities are usually one-shot-sessions, but since WebSockets in general are a session based connection, the slimWS.WS_CLIENT_IDENTITY persists over requests - as there are no socket.close() event for that protocol. slimHTTP honors the keep-alive in the identity and doesn’t touch the socket after each response.