HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulewai-websockets-3.0.1.2Haskell98

Network.Wai.Handler.WebSockets

  • 5 values

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 :: Application
app = websocketsOr defaultConnectionOptions wsApp backupApp
  where
    wsApp :: ServerApp
    wsApp pending_conn = do
        conn <- acceptRequest pending_conn
        sendTextData conn ("Hello, client!" :: Text)

    backupApp :: Application
    backupApp _ respond = respond $ responseLBS Network.HTTP.Types.status400 [] "Not a WebSocket request"