module Network.HTTP.Lucu.Abortion.Internal
( Abortion(..)
, abortPage
)
where
import Blaze.ByteString.Builder (Builder)
import Control.Exception
import Text.Blaze
import Data.Monoid.Unicode
import Data.Text (Text)
import Data.Typeable
import Network.HTTP.Lucu.Config
import Network.HTTP.Lucu.DefaultPage
import Network.HTTP.Lucu.Headers
import Network.HTTP.Lucu.Request
import Network.HTTP.Lucu.Response
import Network.HTTP.Lucu.Response.StatusCode
data Abortion = Abortion {
aboStatus ∷ !SomeStatusCode
, aboHeaders ∷ !Headers
, aboMessage ∷ !(Maybe Text)
} deriving (Eq, Show, Typeable)
instance Exception Abortion
instance HasHeaders Abortion where
getHeaders = aboHeaders
setHeaders abo hdr = abo { aboHeaders = hdr }
abortPage ∷ Config → Maybe Request → Response → Abortion → Builder
abortPage conf req res abo
= case aboMessage abo of
Just msg
→ defaultPageWithMessage conf (aboStatus abo) $ toHtml msg
Nothing
→ let res' = res {
resStatus = aboStatus abo
, resHeaders = resHeaders res ⊕ aboHeaders abo
}
in
defaultPageForResponse conf req res'