Bases: object
WSGI middleware that performs the WebSocket upgrade handshake.
1 2 3 4 | def ws_handler(websocket):
...
app = WebSocketUpgradeMiddleware(ws_handler)
|
If the handshake succeeds, it calls app with an instance of websocket_class with a copy of the environ dictionary.
If an error occurs and fallback_app is provided, it must be a WSGI application which will be called. Otherwise it returns a simple error through the inner start_response.
One interesting aspect is that wsgiref fails with this middleware due to the Upgrade hop-by-hop header which is not allowed.
Make sure that your server does not close the underlying socket for you since it would close the whole WebSocket connection as well.
You may provide your own representation of the socket by setting the environ key: 'upgrade.socket'. Otherwise, 'wsgi.input'._sock will be used.