Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data WebServer m a where
- StartWebServer :: Port -> (Request -> PendingWebRequest -> m ResponseReceived) -> WebServer m ()
- StartWebServerSettings :: Settings -> (Request -> PendingWebRequest -> m ResponseReceived) -> WebServer m ()
- RespondWebRequest :: PendingWebRequest -> Response -> WebServer m ResponseReceived
- GetBody :: Int -> Request -> WebServer m (Maybe ByteString)
- UpgradeToWebSocketsResponse :: ConnectionOptions -> (PendingConnection -> m ()) -> Request -> WebServer m (Maybe Response)
- AcceptPendingWebSocketConnection :: PendingConnection -> AcceptRequest -> WebServer m (Either (Either HandshakeException ConnectionException) Connection)
- RejectPendingWebSocketConnection :: PendingConnection -> RejectRequest -> WebServer m ()
- WhilePingingWebSocket :: Connection -> Int -> m a -> WebServer m (Maybe a)
- SendWebSocketDataMessages :: Connection -> [DataMessage] -> WebServer m ()
- ReceiveWebSocketDataMessage :: Connection -> WebServer m (Either ConnectionException DataMessage)
- SendWebSocketCloseCode :: WebSocketsData a => Connection -> Word16 -> a -> WebServer m ()
- data PendingWebRequest
- startWebServer :: forall r. Member WebServer r => Port -> (Request -> PendingWebRequest -> Sem r ResponseReceived) -> Sem r ()
- startWebServerSettings :: forall r. Member WebServer r => Settings -> (Request -> PendingWebRequest -> Sem r ResponseReceived) -> Sem r ()
- respondWebRequest :: forall r. Member WebServer r => PendingWebRequest -> Response -> Sem r ResponseReceived
- getBody :: forall r. Member WebServer r => Int -> Request -> Sem r (Maybe ByteString)
- upgradeToWebSocketsResponse :: forall r. Member WebServer r => ConnectionOptions -> (PendingConnection -> Sem r ()) -> Request -> Sem r (Maybe Response)
- acceptPendingWebSocketConnection :: forall r. Member WebServer r => PendingConnection -> AcceptRequest -> Sem r (Either (Either HandshakeException ConnectionException) Connection)
- rejectPendingWebSocketConnection :: forall r. Member WebServer r => PendingConnection -> RejectRequest -> Sem r ()
- whilePingingWebSocket :: forall r a. Member WebServer r => Connection -> Int -> Sem r a -> Sem r (Maybe a)
- sendWebSocketDataMessages :: forall r. Member WebServer r => Connection -> [DataMessage] -> Sem r ()
- receiveWebSocketDataMessage :: forall r. Member WebServer r => Connection -> Sem r (Either ConnectionException DataMessage)
- sendWebSocketCloseCode :: forall r a. (Member WebServer r, WebSocketsData a) => Connection -> Word16 -> a -> Sem r ()
- runWebServerFinal :: Final IO `Member` r => Sem (WebServer ': r) a -> Sem r a
Documentation
data WebServer m a where Source #
StartWebServer :: Port -> (Request -> PendingWebRequest -> m ResponseReceived) -> WebServer m () | Starts a new web-server listening on a port, sending all requests to the provided function. |
StartWebServerSettings :: Settings -> (Request -> PendingWebRequest -> m ResponseReceived) -> WebServer m () | |
RespondWebRequest :: PendingWebRequest -> Response -> WebServer m ResponseReceived | Responds to a web request (usually called from the callback to StartWebServer. |
GetBody :: Int -> Request -> WebServer m (Maybe ByteString) | Reads the entire body of a request into memory. Takes a maximum length to read - if the body length exceeds this length, returns Nothing. |
UpgradeToWebSocketsResponse :: ConnectionOptions -> (PendingConnection -> m ()) -> Request -> WebServer m (Maybe Response) | Builds a response to upgrade a connection to a web socket. Returns Nothing if the request is not appropriate to upgrade. |
AcceptPendingWebSocketConnection :: PendingConnection -> AcceptRequest -> WebServer m (Either (Either HandshakeException ConnectionException) Connection) | Accepts a pending WebSockets connection. |
RejectPendingWebSocketConnection :: PendingConnection -> RejectRequest -> WebServer m () | Rejects a pending WebSockets connection. |
WhilePingingWebSocket :: Connection -> Int -> m a -> WebServer m (Maybe a) | Runs an app, and sends a ping message over the WebSockets connection every n seconds while the app is executing. When the app completes, the pings will also stop. |
SendWebSocketDataMessages :: Connection -> [DataMessage] -> WebServer m () | Sends some data messages over the WebSockets connection. |
ReceiveWebSocketDataMessage :: Connection -> WebServer m (Either ConnectionException DataMessage) | Receives a data message from the WebSockets connection. Returns a
Left |
SendWebSocketCloseCode :: WebSocketsData a => Connection -> Word16 -> a -> WebServer m () | Sends a friendly close message and close code on a WebSocket. See http://tools.ietf.org/html/rfc6455#section-7.4 for a list of close codes. |
data PendingWebRequest Source #
startWebServer :: forall r. Member WebServer r => Port -> (Request -> PendingWebRequest -> Sem r ResponseReceived) -> Sem r () Source #
Starts a new web-server listening on a port, sending all requests to the provided function.
startWebServerSettings :: forall r. Member WebServer r => Settings -> (Request -> PendingWebRequest -> Sem r ResponseReceived) -> Sem r () Source #
respondWebRequest :: forall r. Member WebServer r => PendingWebRequest -> Response -> Sem r ResponseReceived Source #
Responds to a web request (usually called from the callback to StartWebServer.
getBody :: forall r. Member WebServer r => Int -> Request -> Sem r (Maybe ByteString) Source #
Reads the entire body of a request into memory. Takes a maximum length to read - if the body length exceeds this length, returns Nothing.
upgradeToWebSocketsResponse :: forall r. Member WebServer r => ConnectionOptions -> (PendingConnection -> Sem r ()) -> Request -> Sem r (Maybe Response) Source #
Builds a response to upgrade a connection to a web socket. Returns Nothing if the request is not appropriate to upgrade.
acceptPendingWebSocketConnection :: forall r. Member WebServer r => PendingConnection -> AcceptRequest -> Sem r (Either (Either HandshakeException ConnectionException) Connection) Source #
Accepts a pending WebSockets connection.
rejectPendingWebSocketConnection :: forall r. Member WebServer r => PendingConnection -> RejectRequest -> Sem r () Source #
Rejects a pending WebSockets connection.
whilePingingWebSocket :: forall r a. Member WebServer r => Connection -> Int -> Sem r a -> Sem r (Maybe a) Source #
Runs an app, and sends a ping message over the WebSockets connection every n seconds while the app is executing. When the app completes, the pings will also stop.
sendWebSocketDataMessages :: forall r. Member WebServer r => Connection -> [DataMessage] -> Sem r () Source #
Sends some data messages over the WebSockets connection.
receiveWebSocketDataMessage :: forall r. Member WebServer r => Connection -> Sem r (Either ConnectionException DataMessage) Source #
Receives a data message from the WebSockets connection. Returns a
Left WS.CloseRequest if the connection is closed cleanly. Returns a
Left
WS.ConnectionClosed if the
connection is closed uncleanly.
sendWebSocketCloseCode :: forall r a. (Member WebServer r, WebSocketsData a) => Connection -> Word16 -> a -> Sem r () Source #
Sends a friendly close message and close code on a WebSocket. See http://tools.ietf.org/html/rfc6455#section-7.4 for a list of close codes.