Safe Haskell | None |
---|---|
Language | Haskell98 |
- 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 Source
Upgrade a websockets
ServerApp
to a wai
Application
. Uses
the given backup Application
to handle Request
s that are not
WebSocket requests.
websocketsOr opts ws_app backup_app = \req send_response -> casewebsocketsApp
opts ws_app req ofNothing
-> backup_app req send_responseJust
res -> send_response res
For example, below is an Application
that sends "Hello, client!"
to
each connected client.
app ::Application
app =websocketsOr
defaultConnectionOptions
wsApp backupApp where wsApp ::ServerApp
wsApp pending_conn = do conn <-acceptRequest
pending_connsendTextData
conn ("Hello, client!" ::Text
) backupApp ::Application
backupApp =respondLBS
status400
[] "Not a WebSocket request"
websocketsApp :: ConnectionOptions -> ServerApp -> Request -> Maybe Response Source
isWebSocketsReq :: Request -> Bool Source
Returns whether or not the given Request
is a WebSocket request.
runWebSockets :: ConnectionOptions -> RequestHead -> (PendingConnection -> IO a) -> IO ByteString -> (ByteString -> IO ()) -> IO a Source
Internal function to run the WebSocket io-streams using the conduit library.