| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Network.Wai.Handler.WebSockets
- websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application
- websocketsApp :: ConnectionOptions -> ServerApp -> Request -> Maybe Response
- isWebSocketsReq :: Request -> Bool
- getRequestHead :: Request -> RequestHead
- runWebSockets :: ConnectionOptions -> RequestHead -> (PendingConnection -> IO a) -> IO ByteString -> (ByteString -> IO ()) -> IO a
Documentation
websocketsOr :: ConnectionOptions -> ServerApp -> Application -> Application #
Upgrade a websockets ServerApp to a wai Application. Uses
the given backup Application to handle Requests that are not
WebSocket requests.
websocketsOr opts ws_app backup_app = \req respond ->
case websocketsApp opts ws_app req of
Nothing -> backup_app req send_response
Just res -> respond res
For example, below is an Application that sends "Hello, client!" to
each connected client.
app ::Applicationapp =websocketsOrdefaultConnectionOptionswsApp backupApp where wsApp ::ServerAppwsApp pending_conn = do conn <-acceptRequestpending_connsendTextDataconn ("Hello, client!" ::Text) backupApp ::ApplicationbackupApp _ respond = respond $responseLBSstatus400[] "Not a WebSocket request"
websocketsApp :: ConnectionOptions -> ServerApp -> Request -> Maybe Response #
isWebSocketsReq :: Request -> Bool #
Returns whether or not the given Request is a WebSocket request.
getRequestHead :: Request -> RequestHead #
runWebSockets :: ConnectionOptions -> RequestHead -> (PendingConnection -> IO a) -> IO ByteString -> (ByteString -> IO ()) -> IO a #
Internal function to run the WebSocket io-streams using the conduit library.