X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FAbortion.hs;h=4313df3ec42adee37f7df9689fb5ff0b8cba4219;hp=0a42d71353b552bdbff1fc7231f0f0d39f87756b;hb=858129cb755aa09da2b7bd758efb8519f2c89103;hpb=5b255535f2c7d2a6d4622ad164b31e63746b906e diff --git a/Network/HTTP/Lucu/Abortion.hs b/Network/HTTP/Lucu/Abortion.hs index 0a42d71..4313df3 100644 --- a/Network/HTTP/Lucu/Abortion.hs +++ b/Network/HTTP/Lucu/Abortion.hs @@ -24,6 +24,7 @@ import Network.HTTP.Lucu.Headers import Network.HTTP.Lucu.HttpVersion import Network.HTTP.Lucu.Request import Network.HTTP.Lucu.Response +import {-# SOURCE #-} Network.HTTP.Lucu.Resource import System.IO.Unsafe import Text.XML.HXT.Arrow.WriteDocument import Text.XML.HXT.Arrow.XmlArrow @@ -32,9 +33,9 @@ import Text.XML.HXT.DOM.XmlKeywords data Abortion = Abortion { - aboStatus :: StatusCode - , aboHeaders :: Headers - , aboMessage :: Maybe String + aboStatus :: !StatusCode + , aboHeaders :: !Headers + , aboMessage :: !(Maybe String) } deriving (Show, Typeable) -- | Computation of @'abort' status headers msg@ aborts the @@ -62,30 +63,34 @@ data Abortion = Abortion { -- > (Just "It has been moved to example.net") abort :: MonadIO m => StatusCode -> [ (String, String) ] -> Maybe String -> m a abort status headers msg - = let abo = Abortion status headers msg + = status `seq` headers `seq` msg `seq` + let abo = Abortion status headers msg exc = DynException (toDyn abo) in liftIO $ throwIO exc +{-# SPECIALIZE abort :: StatusCode -> [ (String, String) ] -> Maybe String -> Resource a #-} -- | Computation of @'abortSTM' status headers msg@ just computes -- 'abort' in a STM monad. abortSTM :: StatusCode -> [ (String, String) ] -> Maybe String -> STM a abortSTM status headers msg - = unsafeIOToSTM $ abort status headers msg + = status `seq` headers `seq` msg `seq` + unsafeIOToSTM $! abort status headers msg -- | Computation of @'abortA' -< (status, (headers, msg))@ just -- computes 'abort' in an ArrowIO. abortA :: ArrowIO a => a (StatusCode, ([ (String, String) ], Maybe String)) c abortA = arrIO3 abort - +{-# SPECIALIZE abortA :: IOSArrow (StatusCode, ([ (String, String) ], Maybe String)) c #-} -- aboMessage が Just なら單に mkDefaultPage に渡すだけで良いので樂だが、 -- Nothing の場合は getDefaultPage を使ってデフォルトのメッセージを得な -- ければならない。 abortPage :: Config -> Maybe Request -> Response -> Abortion -> String abortPage conf reqM res abo - = case aboMessage abo of + = conf `seq` reqM `seq` res `seq` abo `seq` + case aboMessage abo of Just msg -> let [html] = unsafePerformIO $ runX ( mkDefaultPage conf (aboStatus abo) (txt msg)