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

View File

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

View File

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