| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
IHP.Controller.Response
Synopsis
- respondWith :: (?request :: Request, ?respond :: Respond) => Response -> IO ResponseReceived
- respondAndExit :: (?request :: Request, ?respond :: Respond) => Response -> IO a
- addResponseHeaders :: [Header] -> Response -> Response
- addResponseHeadersFromContext :: (?request :: Request) => Response -> IO Response
- earlyReturn :: IO ResponseReceived -> IO a
- newtype EarlyReturnException = EarlyReturnException ResponseReceived
- responseHeadersVaultKey :: Key (IORef [Header])
Documentation
respondWith :: (?request :: Request, ?respond :: Respond) => Response -> IO ResponseReceived Source #
Sends a response to the client. Used by render functions.
This is the normal way to respond - it calls the WAI respond callback directly and returns the ResponseReceived.
respondAndExit :: (?request :: Request, ?respond :: Respond) => Response -> IO a Source #
Sends a response and exits the current action via early return.
Sends the response via respondWith then throws EarlyReturnException
so the action short-circuits.
addResponseHeaders :: [Header] -> Response -> Response Source #
Add headers to current response | Returns a Response with headers
addResponseHeaders [("Content-Type", "text/html")] responseaddResponseHeadersFromContext :: (?request :: Request) => Response -> IO Response Source #
Add headers to current response, getting the headers from the request vault | Returns a Response with headers
addResponseHeadersFromContext response
You probabaly want setHeader
earlyReturn :: IO ResponseReceived -> IO a Source #
Exit a request handler early after sending a response.
Use this when you want to conditionally exit a handler:
handler = do
when someCondition do
earlyReturn (sendErrorResponse ...)
-- rest of the handler
sendNormalResponseThe function runs the given IO action (which should send a response),
then throws EarlyReturnException to exit. The middleware catches this
exception so it doesn't propagate further.
newtype EarlyReturnException Source #
Exception thrown by earlyReturn to exit a handler after the response has been sent.
Constructors
| EarlyReturnException ResponseReceived |
Instances
| Exception EarlyReturnException | |
Defined in Network.Wai.Middleware.EarlyReturn | |
| Show EarlyReturnException | |
Defined in Network.Wai.Middleware.EarlyReturn Methods showsPrec :: Int -> EarlyReturnException -> ShowS # show :: EarlyReturnException -> String # showList :: [EarlyReturnException] -> ShowS # | |