Spock 0.11.0.0 → 0.12.0.0
raw patch · 6 files changed
+41/−139 lines, 6 filesdep ~Spock-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: Spock-core
API changes (from Hackage documentation)
+ Web.Spock: wildcard :: Path ((:) * Text ([] *)) Closed
- Web.Spock: middleware :: Monad m => Middleware -> SpockCtxT ctx m ()
+ Web.Spock: middleware :: (RouteM t, Monad m) => Middleware -> t ctx m ()
- Web.Spock: prehook :: MonadIO m => ActionCtxT ctx m ctx' -> SpockCtxT ctx' m () -> SpockCtxT ctx m ()
+ Web.Spock: prehook :: (RouteM t, MonadIO m) => ActionCtxT ctx m ctx' -> t ctx' m () -> t ctx m ()
- Web.Spock: renderRoute :: Path as Open -> HVectElim as Text
+ Web.Spock: renderRoute :: AllHave ToHttpApiData as => Path as Open -> HVectElim as Text
- Web.Spock: subcomponent :: Monad m => Path ([] *) Open -> SpockCtxT ctx m () -> SpockCtxT ctx m ()
+ Web.Spock: subcomponent :: (RouteM t, Monad m) => Path ([] *) Open -> t ctx m () -> t ctx m ()
- Web.Spock: var :: (Typeable * a, PathPiece a) => Path ((:) * a ([] *)) Open
+ Web.Spock: var :: (Typeable * a, FromHttpApiData a) => Path ((:) * a ([] *)) Open
Files
- LICENSE +2/−2
- README.md +5/−129
- Spock.cabal +3/−3
- src/Web/Spock.hs +4/−4
- test/Spec.hs +15/−1
- test/Web/Spock/SafeSpec.hs +12/−0
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013 - 2016, Alexander Thiemann <mail@athiemann.net>+Copyright (c) 2013 - 2017, Alexander Thiemann <mail@athiemann.net> All rights reserved. @@ -13,7 +13,7 @@ disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Alexander Thiemann <mail@agrafix.net> nor the names of other+ * Neither the name of Alexander Thiemann nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.
README.md view
@@ -4,138 +4,14 @@ [](https://travis-ci.org/agrafix/Spock) [](http://hackage.haskell.org/package/Spock) +Documentation: [Spock 0.12.0.0](https://spockdocs.s3.eu-central-1.amazonaws.com/Spock-0.12.0.0/Web-Spock.html)+ ## Intro Hackage: [Spock](http://hackage.haskell.org/package/Spock) Stackage: [Spock](https://www.stackage.org/package/Spock) -Another Haskell web framework for rapid development---## Library Usage Example--```haskell-{-# LANGUAGE OverloadedStrings #-}-import Web.Spock--import qualified Data.Text as T--main =- runSpock 3000 $ spockT id $- do get ("echo" <//> var) $ \something ->- text $ T.concat ["Echo: ", something]--```--## Install--* Using cabal: `cabal install Spock`-* Using Stack: `stack install Spock`-* From Source (cabal): `git clone https://github.com/agrafix/Spock.git && cd Spock && cabal install`-* From Source (stack): `git clone https://github.com/agrafix/Spock.git && cd Spock && stack build`--## Mailing list--Please join our mailing list at haskell-spock@googlegroups.com--## Features--Another Haskell web framework for rapid development: This toolbox provides-everything you need to get a quick start into web hacking with haskell:--* fast typesafe routing-* middleware-* json-* sessions-* cookies-* database helper-* csrf-protection-* typesafe contexts--## Important Links--* [Tutorial](https://www.spock.li/tutorial/)-* [Type-safe routing in Spock](https://www.spock.li/2015/04/19/type-safe_routing.html)-* [Taking Authentication to the next Level](https://www.spock.li/2015/08/23/taking_authentication_to_the_next_level.html)--### Talks--* English: [Spock - Powerful Elegent Web Applications using Haskell](https://www.youtube.com/watch?v=kNqsOBrCbLo) (by Alexander Thiemann)-* English: [Beginning Web Programming in Haskell (using Spock)](https://www.youtube.com/watch?v=GobPiGL9jJ4) (by Ollie Charles)-* German: [Moderne typsichere Web-Entwicklung mit Haskell](https://dl.dropboxusercontent.com/u/15078797/talks/typesafe-webdev-2015.pdf) (by Alexander Thiemann)-* German: [reroute-talk](https://github.com/timjb/reroute-talk) (by Tim Baumann)--## Candy--### Extensions--The following Spock extensions exist:--* Background workers for Spock: [Spock-worker](http://hackage.haskell.org/package/Spock-worker)-* Digestive functors for Spock: [Spock-digestive](http://hackage.haskell.org/package/Spock-digestive)--### Works well with Spock--* User management [users](http://hackage.haskell.org/package/users)-* Data validation [validate-input](http://hackage.haskell.org/package/validate-input)-* Blaze bootstrap helpers [blaze-bootstrap](http://hackage.haskell.org/package/blaze-bootstrap)-* digestive-forms bootstrap helpers [digestive-bootstrap](http://hackage.haskell.org/package/digestive-bootstrap)--### SSL / HTTPS--If you'd like to use your application via HTTPS, there are two options:--* Use nginx/haproxy/... as reverse proxy in front of the Spock application.-* Convert the Spock application to a `wai`-application using the `spockAsApp`. Then use the `warp-tls` package to run it.--### Benchmarks--See the [Spock-bench repository](https://github.com/agrafix/Spock-bench) to reproduce.--| Framework | GHC | Version | simple route | route with one param | deeply nested route |-|-----------|--------|----------|---------------------------|---------------------------|---------------------|-| Spock | 7.10.2 | 0.11.0.0 | **69243** | **65835** | **64763** |-| scotty | 7.10.2 | 0.10.2 | 66441 | 65357 | 9542 |-| snap | 7.10.2 | 0.9.8.0 | 39964 | 35566 | 38356 |-| fn | 7.10.2 | 0.2.0.2 | 63083 | 63183 | 22346 |-| servant | 7.10.2 | 0.7 | 66041 | 65590 | 64606 |--## Example Projects--* [funblog](https://github.com/agrafix/funblog)-* [makeci](https://github.com/openbrainsrc/makeci)-* [curry-recipes](https://github.com/timjb/reroute-talk/tree/06574561918b50c1809f1e24ec7faeff731fddcf/curry-recipes)--## Notes--Since version 0.11.0.0 Spock drops simple routing in favor of typesafe routing and drops safe actions in favor of the "usual" way of csrf protection with a token.--Since version 0.7.0.0 Spock supports typesafe routing. If you wish to continue using the untyped version of Spock you can Use `Web.Spock.Simple`. The implementation of the routing is implemented in a separate haskell package called `reroute`.--Since version 0.5.0.0 Spock is no longer built on top of scotty. The-design and interface is still influenced by scotty, but the internal-implementation differs from scotty's.--## Thanks to--* Tim Baumann [Github](https://github.com/timjb) (lot's of help with typesafe routing)-* Tom Nielsen [Github](https://github.com/glutamate) (much feedback and small improvements)-* ... and all other awesome [contributors](https://github.com/agrafix/Spock/graphs/contributors)!--## Hacking--Pull requests are welcome! Please consider creating an issue beforehand, so we can discuss what you would like to do. Code should be written in a consistent style throughout the project. Avoid whitespace that is sensible to conflicts. (E.g. alignment of `=` signs in functions definitions) Note that by sending a pull request you agree that your contribution can be released under the BSD3 License as part of the `Spock` package or related packages.---## Misc--### Supported GHC Versions--* 7.8.4-* 7.10.2-* 8.0--### License+Another Haskell web framework for rapid development. To get started with Spock, check our [tutorial](https://www.spock.li/tutorial/)+or take a quick look at our example projects. -Released under the BSD3 license.-(c) 2013 - 2016 Alexander Thiemann+For more information please visit our homepage at [www.spock.li](https://www.spock.li)
Spock.cabal view
@@ -1,5 +1,5 @@ name: Spock-version: 0.11.0.0+version: 0.12.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: .@@ -24,11 +24,11 @@ license-file: LICENSE author: Alexander Thiemann <mail@athiemann.net> maintainer: Alexander Thiemann <mail@athiemann.net>-copyright: (c) 2013 - 2016 Alexander Thiemann+copyright: (c) 2013 - 2017 Alexander Thiemann category: Web build-type: Simple cabal-version: >=1.8-tested-with: GHC==7.8.4, GHC==7.10.2, GHC==8.0.1+tested-with: GHC==7.10.2, GHC==8.0.1 extra-source-files: README.md
src/Web/Spock.hs view
@@ -6,12 +6,12 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} module Web.Spock- ( -- * Lauching Spock+ ( -- * Launching Spock runSpock, runSpockNoBanner, spockAsApp -- * Spock's route definition monad , spock, SpockM, SpockCtxM -- * Defining routes- , Path, root, Var, var, static, (<//>)+ , Path, root, Var, var, static, (<//>), wildcard -- * Rendering routes , renderRoute -- * Hooking routes@@ -49,8 +49,8 @@ import Control.Applicative import Control.Monad.Reader import Control.Monad.Trans.Resource-import Network.HTTP.Types.Status (status403) import Data.Pool+import Network.HTTP.Types.Status (status403) import Prelude hiding (head) import qualified Data.HVect as HV import qualified Data.Text as T@@ -122,7 +122,7 @@ {-# INLINE getClientCsrfToken #-} -- | Check that the client sent a valid CSRF token. You should not need to call this--- manually if 'spc_csrfProtection' is turned on.+-- manually in non GET requests if 'spc_csrfProtection' is turned on. csrfCheck :: SpockActionCtx ctx conn sess st () csrfCheck = do csrf <- getCsrfToken
test/Spec.hs view
@@ -1,1 +1,15 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}+module Main where++import qualified Web.Spock.CsrfSpec+import qualified Web.Spock.Internal.SessionManagerSpec+import qualified Web.Spock.Internal.SessionVaultSpec+import qualified Web.Spock.SafeSpec++import Test.Hspec++main :: IO ()+main = hspec $+ do Web.Spock.Internal.SessionVaultSpec.spec+ Web.Spock.Internal.SessionManagerSpec.spec+ Web.Spock.SafeSpec.spec+ Web.Spock.CsrfSpec.spec
test/Web/Spock/SafeSpec.hs view
@@ -12,6 +12,7 @@ import Data.IORef import Data.Monoid import Test.Hspec+import qualified Data.ByteString.Lazy.Char8 as BSLC import qualified Data.HashSet as HS import qualified Data.Text as T import qualified Data.Text.Encoding as T@@ -41,6 +42,12 @@ Test.request "GET" "/check" [("Cookie", T.encodeUtf8 $ "spockcookie=" <> sessCookie)] "" `Test.shouldRespondWith` "5" Test.with sessionApp $+ it "should update internal session id correctly" $+ do bdy <- fmap Wai.simpleBody (Test.get "/regenerate-different-sids")+ case BSLC.split '|' bdy of+ [a, b] | a /= b -> pure ()+ xs -> Test.liftIO $ expectationFailure ("Bad result: " ++ show xs)+ Test.with sessionApp $ it "should regenerate and preserve all content" $ do res <- Test.get "/set/5" case getSessCookie res of@@ -64,6 +71,11 @@ do get "test" $ getSessionId >>= text get ("set" <//> var) $ \number -> writeSession number >> text "done" get "regenerate" $ sessionRegenerateId >> text "done"+ get "regenerate-different-sids" $+ do s1 <- getSessionId+ sessionRegenerateId+ s2 <- getSessionId+ text $ s1 <> "|" <> s2 get "check" $ do val <- readSession text (T.pack $ show val)