]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/Abortion.hs
Small fix
[Lucu.git] / Network / HTTP / Lucu / Abortion.hs
index 9ff629df73e84db0eac2a50073e06b2494eb120b..dc33eb125bfda4027413bb5782aaac51b09cca8c 100644 (file)
@@ -5,6 +5,7 @@
 module Network.HTTP.Lucu.Abortion
     ( Abortion(..)
     , abort
+    , abortPurely
     , abortSTM
     , abortA
     , abortPage
@@ -16,8 +17,9 @@ import           Control.Arrow.ArrowIO
 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
@@ -63,10 +65,17 @@ data Abortion = Abortion {
 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.
@@ -99,7 +108,7 @@ abortPage conf reqM res abo
         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''