Added sendResponse function
This commit is contained in:
parent
e32c5b9a53
commit
058b738b4a
@ -43,8 +43,9 @@ module Yesod.Handler
|
|||||||
, badMethod
|
, badMethod
|
||||||
, permissionDenied
|
, permissionDenied
|
||||||
, invalidArgs
|
, invalidArgs
|
||||||
-- ** Sending static files
|
-- ** Short-circuit responses.
|
||||||
, sendFile
|
, sendFile
|
||||||
|
, sendResponse
|
||||||
-- * Setting headers
|
-- * Setting headers
|
||||||
, setCookie
|
, setCookie
|
||||||
, deleteCookie
|
, deleteCookie
|
||||||
@ -94,6 +95,7 @@ import Text.Hamlet
|
|||||||
import Numeric (showIntAtBase)
|
import Numeric (showIntAtBase)
|
||||||
import Data.Char (ord, chr)
|
import Data.Char (ord, chr)
|
||||||
|
|
||||||
|
-- | The type-safe URLs associated with a site argument.
|
||||||
data family Routes a
|
data family Routes a
|
||||||
|
|
||||||
data HandlerData sub master = HandlerData
|
data HandlerData sub master = HandlerData
|
||||||
@ -116,6 +118,8 @@ handlerSubData tm ts route hd = hd
|
|||||||
, handlerRoute = Just route
|
, handlerRoute = Just route
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- | Used internally for promoting subsite handler functions to master site
|
||||||
|
-- handler functions. Should not be needed by users.
|
||||||
toMasterHandler :: (Routes sub -> Routes master)
|
toMasterHandler :: (Routes sub -> Routes master)
|
||||||
-> (master -> sub)
|
-> (master -> sub)
|
||||||
-> Routes sub
|
-> Routes sub
|
||||||
@ -125,8 +129,10 @@ toMasterHandler tm ts route (GHandler h) =
|
|||||||
GHandler $ withReaderT (handlerSubData tm ts route) h
|
GHandler $ withReaderT (handlerSubData tm ts route) h
|
||||||
|
|
||||||
-- | A generic handler monad, which can have a different subsite and master
|
-- | A generic handler monad, which can have a different subsite and master
|
||||||
-- site. This monad is a combination of reader for basic arguments, a writer
|
-- site. This monad is a combination of 'ReaderT' for basic arguments, a
|
||||||
-- for headers, and an error-type monad for handling special responses.
|
-- 'WriterT' for headers and session, and an 'MEitherT' monad for handling
|
||||||
|
-- special responses. It is declared as a newtype to make compiler errors more
|
||||||
|
-- readable.
|
||||||
newtype GHandler sub master a = GHandler { unGHandler ::
|
newtype GHandler sub master a = GHandler { unGHandler ::
|
||||||
ReaderT (HandlerData sub master) (
|
ReaderT (HandlerData sub master) (
|
||||||
MEitherT HandlerContents (
|
MEitherT HandlerContents (
|
||||||
@ -352,6 +358,10 @@ getMessage = do
|
|||||||
sendFile :: ContentType -> FilePath -> GHandler sub master a
|
sendFile :: ContentType -> FilePath -> GHandler sub master a
|
||||||
sendFile ct = GHandler . lift . throwMEither . HCSendFile ct
|
sendFile ct = GHandler . lift . throwMEither . HCSendFile ct
|
||||||
|
|
||||||
|
-- | Bypass remaining handler code and output the given content.
|
||||||
|
sendResponse :: HasReps c => c -> GHandler sub master a
|
||||||
|
sendResponse = GHandler . lift . throwMEither . HCContent . chooseRep
|
||||||
|
|
||||||
-- | Return a 404 not found page. Also denotes no handler available.
|
-- | Return a 404 not found page. Also denotes no handler available.
|
||||||
notFound :: Failure ErrorResponse m => m a
|
notFound :: Failure ErrorResponse m => m a
|
||||||
notFound = failure NotFound
|
notFound = failure NotFound
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user