Spock 0.12.0.0 → 0.13.0.0
raw patch · 6 files changed
+37/−5 lines, 6 filesdep ~Spock-coredep ~reroutePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: Spock-core, reroute
API changes (from Hackage documentation)
- Web.Spock: subcomponent :: (RouteM t, Monad m) => Path ([] *) Open -> t ctx m () -> t ctx m ()
+ Web.Spock: hookAnyAll :: ([Text] -> SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st ()
+ Web.Spock: hookRouteAll :: HasRep xs => RouteSpec xs ps ctx conn sess st
+ Web.Spock.Config: [spc_logError] :: SpockCfg conn sess st -> Text -> IO ()
- Web.Spock: (<//>) :: Path as Open -> Path bs ps -> Path (Append as bs) ps
+ Web.Spock: (<//>) :: () => Path as Open -> Path bs ps -> Path Append as bs ps
- Web.Spock: class HasSpock m where type SpockConn m :: * type SpockState m :: * type SpockSession m :: * where {
+ Web.Spock: class HasSpock m where {
- Web.Spock: root :: Path ([] *) Open
+ Web.Spock: root :: Path [] * Open
- Web.Spock: static :: String -> Path ([] *) Open
+ Web.Spock: static :: String -> Path [] * Open
- Web.Spock: type Var a = Path ((:) * a ([] *)) Open
+ Web.Spock: type Var a = Path (:) * a [] * Open
- Web.Spock: var :: (Typeable * a, FromHttpApiData a) => Path ((:) * a ([] *)) Open
+ Web.Spock: var :: (Typeable * a, FromHttpApiData a) => Path (:) * a [] * Open
- Web.Spock: wildcard :: Path ((:) * Text ([] *)) Closed
+ Web.Spock: wildcard :: Path (:) * Text [] * Closed
- Web.Spock.Config: SpockCfg :: st -> PoolOrConn conn -> SessionCfg conn sess st -> Maybe Word64 -> (Status -> ActionCtxT () IO ()) -> Bool -> Text -> Text -> SpockCfg conn sess st
+ Web.Spock.Config: SpockCfg :: st -> PoolOrConn conn -> SessionCfg conn sess st -> Maybe Word64 -> (Status -> ActionCtxT () IO ()) -> (Text -> IO ()) -> Bool -> Text -> Text -> SpockCfg conn sess st
- Web.Spock.Internal.SessionManager: SessionManager :: m SessionId -> m Text -> m () -> m sess -> (sess -> m ()) -> (forall a. (sess -> (sess, a)) -> m a) -> ((forall n. Monad n => sess -> n sess) -> m ()) -> (MonadIO m => m ()) -> Middleware -> IO () -> SessionManager m conn sess st
+ Web.Spock.Internal.SessionManager: SessionManager :: m SessionId -> m Text -> m () -> m sess -> (sess -> m ()) -> (forall a. (sess -> (sess, a)) -> m a) -> ((forall n. Monad n => sess -> n sess) -> m ()) -> MonadIO m => m () -> Middleware -> IO () -> SessionManager m conn sess st
- Web.Spock.Internal.SessionVault: class (Eq (SessionKey s), Hashable (SessionKey s)) => IsSession s where type SessionKey s :: * where {
+ Web.Spock.Internal.SessionVault: class (Eq (SessionKey s), Hashable (SessionKey s)) => IsSession s where {
Files
- Spock.cabal +4/−4
- src/Web/Spock.hs +14/−1
- src/Web/Spock/Config.hs +9/−0
- src/Web/Spock/Internal/Types.hs +2/−0
- test/Web/Spock/CsrfSpec.hs +4/−0
- test/Web/Spock/SafeSpec.hs +4/−0
Spock.cabal view
@@ -1,5 +1,5 @@ name: Spock-version: 0.12.0.0+version: 0.13.0.0 synopsis: Another Haskell web framework for rapid development description: This toolbox provides everything you need to get a quick start into web hacking with haskell: .@@ -45,7 +45,7 @@ Web.Spock.Internal.Monad, Web.Spock.Internal.Types build-depends:- Spock-core >= 0.11,+ Spock-core >= 0.13, base >= 4 && < 5, base64-bytestring >=1.0, bytestring >=0.10,@@ -58,7 +58,7 @@ list-t >=0.4, monad-control >=1.0, mtl >=2.1,- reroute >=0.3.1,+ reroute >=0.5, resource-pool >=0.2, resourcet >= 0.4, stm >=2.4,@@ -70,7 +70,7 @@ unordered-containers >=0.2, vault >=0.3, wai >=3.0- ghc-options: -auto-all -Wall -fno-warn-orphans+ ghc-options: -Wall -fno-warn-orphans test-suite spocktests type: exitcode-stdio-1.0
src/Web/Spock.hs view
@@ -15,10 +15,12 @@ -- * Rendering routes , renderRoute -- * Hooking routes- , subcomponent, prehook+ , prehook , RouteSpec , get, post, getpost, head, put, delete, patch, hookRoute , hookRouteCustom, hookAny, hookAnyCustom+ , hookRouteAll+ , hookAnyAll , C.StdMethod (..) -- * Adding Wai.Middleware , middleware@@ -39,6 +41,7 @@ ( hookRoute', hookAny' , get, post, getpost, head, put, delete, patch, hookRoute , hookRouteCustom, hookAny, hookAnyCustom+ , hookRouteAll, hookAnyAll ) import Web.Spock.Internal.Monad import Web.Spock.Internal.SessionManager@@ -95,6 +98,7 @@ defaultSpockConfig { sc_maxRequestSize = spc_maxRequestSize spockCfg , sc_errorHandler = spc_errorHandler spockCfg+ , sc_logError = spc_logError spockCfg } spockConfigT coreConfig (\m -> runResourceT $ runReaderT (runWebStateT m) internalState) $ do middleware (sm_middleware $ web_sessionMgr internalState)@@ -145,6 +149,10 @@ hookRoute :: HV.HasRep xs => StdMethod -> RouteSpec xs ps ctx conn sess st hookRoute = hookRoute' . MethodStandard . HttpMethod +-- | Specify an action that will be run regardless of the HTTP verb+hookRouteAll :: HV.HasRep xs => RouteSpec xs ps ctx conn sess st+hookRouteAll = hookRoute' MethodAny+ -- | Specify an action that will be run when the HTTP verb 'GET' and the given route match get :: HV.HasRep xs => RouteSpec xs ps ctx conn sess st get = hookRoute GET@@ -182,6 +190,11 @@ hookAny :: StdMethod -> ([T.Text] -> SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st () hookAny = hookAny' . MethodStandard . HttpMethod++-- | Specify an action that will be run regardless of the HTTP verb and no defined route matches.+-- The full path is passed as an argument+hookAnyAll :: ([T.Text] -> SpockActionCtx ctx conn sess st ()) -> SpockCtxM ctx conn sess st ()+hookAnyAll = hookAny' MethodAny -- | Specify an action that will be run when a custom HTTP verb matches but no defined route matches. -- The full path is passed as an argument
src/Web/Spock/Config.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} module Web.Spock.Config ( SpockCfg (..), defaultSpockCfg@@ -15,10 +16,17 @@ import Web.Spock.Internal.Types import qualified Web.Spock.Internal.SessionVault as SV +#if MIN_VERSION_base(4,11,0)+#elif MIN_VERSION_base(4,9,0)+import Data.Semigroup+#else import Data.Monoid+#endif import Network.HTTP.Types.Status+import System.IO import qualified Data.Text as T import qualified Data.Text.Encoding as T+import qualified Data.Text.IO as T -- | NOP session hooks defaultSessionHooks :: SessionHooks a@@ -57,6 +65,7 @@ , spc_database = conn , spc_sessionCfg = defSess , spc_maxRequestSize = Just (5 * 1024 * 1024)+ , spc_logError = T.hPutStrLn stderr , spc_errorHandler = errorHandler , spc_csrfProtection = False , spc_csrfHeaderName = "X-Csrf-Token"
src/Web/Spock/Internal/Types.hs view
@@ -53,6 +53,8 @@ , spc_errorHandler :: Status -> ActionCtxT () IO () -- ^ Custom error handlers for implicit errors such as not matching routes or -- exceptions during a request handler run.+ , spc_logError :: T.Text -> IO ()+ -- ^ Function that should be called to log errors. , spc_csrfProtection :: Bool -- ^ When set to true, all non GET request will require -- either an HTTP-Header 'spc_csrfHeaderName' or a
test/Web/Spock/CsrfSpec.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE DoAndIfThenElse #-}+{-# LANGUAGE CPP #-} module Web.Spock.CsrfSpec (spec) where import Web.Spock.TestUtils@@ -8,7 +9,10 @@ import Web.Spock import Web.Spock.Config +#if MIN_VERSION_base(4,11,0)+#else import Data.Monoid+#endif import Test.Hspec import qualified Data.ByteString.Lazy as BSL import qualified Data.Text.Encoding as T
test/Web/Spock/SafeSpec.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE DoAndIfThenElse #-}+{-# LANGUAGE CPP #-} module Web.Spock.SafeSpec (spec) where import Web.Spock.TestUtils@@ -10,7 +11,10 @@ import Control.Monad import Data.IORef+#if MIN_VERSION_base(4,11,0)+#else import Data.Monoid+#endif import Test.Hspec import qualified Data.ByteString.Lazy.Char8 as BSLC import qualified Data.HashSet as HS