X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FAbortion.hs;h=dc33eb125bfda4027413bb5782aaac51b09cca8c;hb=1e53b8533fa22640147cc4ca4ce5075c8e39b0d8;hp=9ff629df73e84db0eac2a50073e06b2494eb120b;hpb=0dc3d31312a12f2b085242841b29eb0d96e9c4ac;p=Lucu.git diff --git a/Network/HTTP/Lucu/Abortion.hs b/Network/HTTP/Lucu/Abortion.hs index 9ff629d..dc33eb1 100644 --- a/Network/HTTP/Lucu/Abortion.hs +++ b/Network/HTTP/Lucu/Abortion.hs @@ -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''