ihp-1.5.0: Haskell Web Framework
Safe HaskellNone
LanguageGHC2021

IHP.Controller.Response

Synopsis

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")] response

addResponseHeadersFromContext :: (?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
    sendNormalResponse

The 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.