defaultMiddlewares and MonadCatch instance

This commit is contained in:
Michael Snoyman 2014-04-10 15:04:29 +03:00
parent 3f4a870b86
commit b8a73d9b7f
3 changed files with 20 additions and 6 deletions

View File

@ -27,6 +27,7 @@ module Yesod.Core.Dispatch
, warpDebug
, warpEnv
, mkDefaultMiddlewares
, defaultMiddlewaresNoLogging
-- * WAI subsites
, WaiSubsite (..)
) where
@ -194,11 +195,13 @@ mkDefaultMiddlewares logger = do
#endif
, outputFormat = Apache FromSocket
}
return $ logWare
. acceptOverride
. autohead
. gzip def
. methodOverride
return $ logWare . defaultMiddlewaresNoLogging
-- | All of the default middlewares, excluding logging.
--
-- Since 1.2.12
defaultMiddlewaresNoLogging :: W.Middleware
defaultMiddlewaresNoLogging = acceptOverride . autohead . gzip def . methodOverride
-- | Deprecated synonym for 'warp'.
warpDebug :: YesodDispatch site => Int -> site -> IO ()

View File

@ -16,6 +16,7 @@ import Control.Arrow (first)
import Control.Exception (Exception)
import Control.Monad (liftM, ap)
import Control.Monad.Base (MonadBase (liftBase))
import Control.Monad.Catch (MonadCatch (..))
import Control.Monad.IO.Class (MonadIO (liftIO))
import Control.Monad.Logger (LogLevel, LogSource,
MonadLogger (..))
@ -62,6 +63,7 @@ import Yesod.Core.Internal.Util (getTime, putTime)
import Control.Monad.Trans.Class (MonadTrans (..))
import Yesod.Routes.Class (RenderRoute (..), ParseRoute (..))
import Control.Monad.Reader (MonadReader (..))
import Prelude hiding (catch)
-- Sessions
type SessionMap = Map Text ByteString
@ -405,6 +407,14 @@ instance MonadTrans (WidgetT site) where
instance MonadThrow m => MonadThrow (WidgetT site m) where
#if MIN_VERSION_resourcet(1,1,0)
throwM = lift . throwM
instance MonadCatch m => MonadCatch (HandlerT site m) where
catch (HandlerT m) c = HandlerT $ \r -> m r `catch` \e -> unHandlerT (c e) r
mask a = HandlerT $ \e -> mask $ \u -> unHandlerT (a $ q u) e
where q u (HandlerT b) = HandlerT (u . b)
uninterruptibleMask a =
HandlerT $ \e -> uninterruptibleMask $ \u -> unHandlerT (a $ q u) e
where q u (HandlerT b) = HandlerT (u . b)
#else
monadThrow = lift . monadThrow
#endif

View File

@ -1,5 +1,5 @@
name: yesod-core
version: 1.2.11.1
version: 1.2.12
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
@ -68,6 +68,7 @@ library
, warp >= 1.3.8
, unix-compat
, conduit-extra
, exceptions
exposed-modules: Yesod.Core
Yesod.Core.Content