module Network.HTTP.Lucu.Abortion
( Abortion(..)
, abort
+ , abortPurely
, abortSTM
, abortA
, abortPage
import Control.Concurrent.STM
import Control.Exception
import Control.Monad.Trans
-import GHC.Conc (unsafeIOToSTM)
+import qualified Data.ByteString.Char8 as C8
import Data.Dynamic
+import GHC.Conc (unsafeIOToSTM)
import Network.HTTP.Lucu.Config
import Network.HTTP.Lucu.DefaultPage
import Network.HTTP.Lucu.Headers
abort :: MonadIO m => StatusCode -> [ (String, String) ] -> Maybe String -> m a
abort status headers msg
= status `seq` headers `seq` msg `seq`
- let abo = Abortion status headers msg
+ let abo = Abortion status (toHeaders $ map pack headers) msg
exc = DynException (toDyn abo)
in
liftIO $ throwIO exc
+ where
+ pack (x, y) = (C8.pack x, C8.pack y)
+
+-- |This is similar to 'abort' but computes it with
+-- 'System.IO.Unsafe.unsafePerformIO'.
+abortPurely :: StatusCode -> [ (String, String) ] -> Maybe String -> a
+abortPurely = ((unsafePerformIO .) .) . abort
-- |Computation of @'abortSTM' status headers msg@ just computes
-- 'abort' in a 'Control.Monad.STM.STM' monad.
Nothing
-> let res' = res { resStatus = aboStatus abo }
res'' = foldl (.) id [setHeader name value
- | (name, value) <- aboHeaders abo]
+ | (name, value) <- fromHeaders $ aboHeaders abo]
$ res'
in
getDefaultPage conf reqM res''