snap-core 0.4.0 → 0.4.0.1
raw patch · 4 files changed
+38/−7 lines, 4 files
Files
- snap-core.cabal +1/−1
- src/Snap/Internal/Http/Types.hs +1/−1
- src/Snap/Iteratee.hs +14/−3
- test/suite/Snap/Iteratee/Tests.hs +22/−2
snap-core.cabal view
@@ -1,5 +1,5 @@ name: snap-core-version: 0.4.0+version: 0.4.0.1 synopsis: Snap: A Haskell Web Framework (Core) description:
src/Snap/Internal/Http/Types.hs view
@@ -529,7 +529,7 @@ --------------------------------------------------------------------------------- | addCookie has been deprecated and will be removed in 0.4. Please use+-- | addCookie has been deprecated and will be removed in 0.5. Please use -- 'addResponseCookie' instead. addCookie :: Cookie -- ^ cookie value -> Response -- ^ response to modify
src/Snap/Iteratee.hs view
@@ -138,17 +138,28 @@ ee <- try $ runIteratee (m `catchError` h) case ee of (Left e) -> runIteratee (handler e)- (Right v) -> return v+ (Right v) -> step v where+ step (Continue k) = return $ Continue (\s -> k s `catch` handler)+ -- don't worry about Error here because the error had to come from the+ -- handler (because of 'catchError' above)+ step y = return y+ -- we can only catch iteratee errors if "e" matches "SomeException" h e = maybe (throwError e) (handler) (fromException e) --block :: m a -> m a- block m = Iteratee $ block $ runIteratee m- unblock m = Iteratee $ unblock $ runIteratee m+ block m = Iteratee $ block $ (runIteratee m >>= step)+ where+ step (Continue k) = return $ Continue (\s -> block (k s))+ step y = return y + unblock m = Iteratee $ unblock $ (runIteratee m >>= step)+ where+ step (Continue k) = return $ Continue (\s -> unblock (k s))+ step y = return y ------------------------------------------------------------------------------
test/suite/Snap/Iteratee/Tests.hs view
@@ -8,8 +8,9 @@ import Control.Concurrent (threadDelay) import qualified Control.Exception as E-import Control.Exception hiding (try, assert)+import Control.Exception hiding (try, assert, throw, catch) import Control.Monad+import Control.Monad.CatchIO import Control.Monad.Identity import Control.Monad.Trans import qualified Data.ByteString.Base16 as B16@@ -18,7 +19,7 @@ import qualified Data.ByteString.Lazy.Char8 as L import Data.Int import Data.Maybe-import Prelude hiding (head, drop, take)+import Prelude hiding (catch, head, drop, take) import System.Timeout import Test.Framework import Test.Framework.Providers.QuickCheck2@@ -78,6 +79,7 @@ , testKillIfTooSlow1 , testKillIfTooSlow2 , testKMP+ , testCatchIO ] testEnumBS :: Test@@ -504,6 +506,24 @@ m <- liftM S.concat $ run_ $ tooSlowEnum 3 $$ iter H.assertEqual "testKillIfTooSlow2" (S.replicate 300 'f') m +++------------------------------------------------------------------------------+testCatchIO :: Test+testCatchIO = testCase "iteratee/monadCatchIO" $ do+ e <- run_ $ enumList 1 ["1", "2", "3", "4", "5"] $$ iter 0+ H.assertBool "handled exception" $ isJust e++ where+ iter !i = (continue $ k (i::Int)) `catch` h++ k _ EOF = return Nothing+ k i _ = if i >= 2+ then throw $ ErrorCall "should not escape!"+ else iter (i+1)++ h :: SomeException -> Iteratee ByteString IO (Maybe String)+ h e = return $ Just $ show e ------------------------------------------------------------------------------ tooSlowEnum :: Int -> Enumerator ByteString IO a