git.iko.soy/typeable/servant
on be4f08a help sign in
16 files changed+69−20
since splitsnapshots
unifiedsplit
doc/tutorial/tutorial.cabal+1−1 servant-blaze/servant-blaze.cabal+1−1 servant-cassava/servant-cassava.cabal+1−1 servant-client/servant-client.cabal+1−1 servant-docs/servant-docs.cabal+1−1 servant-foreign/servant-foreign.cabal+1−1 servant-js/servant-js.cabal+1−1 servant-lucid/servant-lucid.cabal+1−1 servant-mock/servant-mock.cabal+1−1 servant-server/servant-server.cabal+1−1 servant-server/src/Servant/Server/Experimental/Auth.hs−1 servant-server/test/Servant/ServerSpec.hs+8−6 servant/servant.cabal+2−1 servant/src/Servant/Utils/Map.hs+20 servant/test/Servant/Utils/MapSpec.hs+27 sources.txt+2−2
doc/tutorial/tutorial.cabal+1−1
@@ -1,5 +1,5 @@
11name: tutorial
2−version: 0.6
2+version: 0.6.1
33synopsis: The servant tutorial
44homepage: http://haskell-servant.github.io/
55license: BSD3
servant-blaze/servant-blaze.cabal+1−1
@@ -2,7 +2,7 @@
22-- documentation, see http://haskell.org/cabal/users-guide/
33
44name: servant-blaze
5−version: 0.6
5+version: 0.6.1
66synopsis: Blaze-html support for servant
77-- description:
88homepage: http://haskell-servant.github.io/
servant-cassava/servant-cassava.cabal+1−1
@@ -2,7 +2,7 @@
22-- documentation, see http://haskell.org/cabal/users-guide/
33
44name: servant-cassava
5−version: 0.6
5+version: 0.6.1
66synopsis: Servant CSV content-type for cassava
77-- description:
88homepage: http://haskell-servant.github.io/
servant-client/servant-client.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-client
2−version: 0.6
2+version: 0.6.1
33synopsis: automatical derivation of querying functions for servant webservices
44description:
55 This library lets you derive automatically Haskell functions that
servant-docs/servant-docs.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-docs
2−version: 0.6
2+version: 0.6.1
33synopsis: generate API docs for your servant webservice
44description:
55 Library for generating API docs from a servant API definition.
servant-foreign/servant-foreign.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-foreign
2−version: 0.6
2+version: 0.6.1
33synopsis: Helpers for generating clients for servant APIs in any programming language
44description:
55 Helper types and functions for generating client functions for servant APIs in any programming language
servant-js/servant-js.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-js
2−version: 0.6
2+version: 0.6.1
33synopsis: Automatically derive javascript functions to query servant webservices.
44description:
55 Automatically derive javascript functions to query servant webservices.
servant-lucid/servant-lucid.cabal+1−1
@@ -2,7 +2,7 @@
22-- documentation, see http://haskell.org/cabal/users-guide/
33
44name: servant-lucid
5−version: 0.6
5+version: 0.6.1
66synopsis: Servant support for lucid
77-- description:
88homepage: http://haskell-servant.github.io/
servant-mock/servant-mock.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-mock
2−version: 0.6
2+version: 0.6.1
33synopsis: Derive a mock server for free from your servant API types
44description:
55 Derive a mock server for free from your servant API types
servant-server/servant-server.cabal+1−1
@@ -1,5 +1,5 @@
11name: servant-server
2−version: 0.6
2+version: 0.6.1
33synopsis: A family of combinators for defining webservices APIs and serving them
44description:
55 A family of combinators for defining webservices APIs and serving them
servant-server/src/Servant/Server/Experimental/Auth.hs−1
@@ -63,4 +63,3 @@ instance ( HasServer api context
6363 where
6464 authHandler = unAuthHandler (getContextEntry context)
6565 authCheck = fmap (either FailFatal Route) . runExceptT . authHandler
66−
servant-server/test/Servant/ServerSpec.hs+8−6
@@ -52,7 +52,7 @@ import Servant.API ((:<|>) (..), (:>), AuthProtect,
5252 Raw, RemoteHost, ReqBody,
5353 StdMethod (..), Verb, addHeader)
5454import Servant.API.Internal.Test.ComprehensiveAPI
55−import Servant.Server (ServantErr (..), Server, err401, err404,
55+import Servant.Server (ServantErr (..), Server, err401, err403, err404,
5656 serve, serveWithContext, Context((:.), EmptyContext))
5757import Test.Hspec (Spec, context, describe, it,
5858 shouldBe, shouldContain)
@@ -606,11 +606,10 @@ type instance AuthServerData (AuthProtect "auth") = ()
606606
607607genAuthContext :: Context '[AuthHandler Request ()]
608608genAuthContext =
609− let authHandler = (\req ->
610− if elem ("Auth", "secret") (requestHeaders req)
611− then return ()
612− else throwE err401
613− )
609+ let authHandler = \req -> case lookup "Auth" (requestHeaders req) of
610+ Just "secret" -> return ()
611+ Just _ -> throwE err403
612+ Nothing -> throwE err401
614613 in mkAuthHandler authHandler :. EmptyContext
615614
616615genAuthSpec :: Spec
@@ -622,6 +621,9 @@ genAuthSpec = do
622621 it "returns 401 when missing headers" $ do
623622 get "/auth" `shouldRespondWith` 401
624623
624+ it "returns 403 on wrong passwords" $ do
625+ THW.request methodGet "/auth" [("Auth","wrong")] "" `shouldRespondWith` 403
626+
625627 it "returns 200 with the right header" $ do
626628 THW.request methodGet "/auth" [("Auth","secret")] "" `shouldRespondWith` 200
627629
servant/servant.cabal+2−1
@@ -1,5 +1,5 @@
11name: servant
2−version: 0.6
2+version: 0.6.1
33synopsis: A family of combinators for defining webservices APIs
44description:
55 A family of combinators for defining webservices APIs and serving them
@@ -96,6 +96,7 @@ test-suite spec
9696 Servant.API.ContentTypesSpec
9797 Servant.API.ResponseHeadersSpec
9898 Servant.Utils.LinksSpec
99+ Servant.Utils.MapSpec
99100 build-depends:
100101 base == 4.*
101102 , aeson
servant/src/Servant/Utils/Map.hsnew file+20
@@ -0,0 +1,20 @@
1+{-# LANGUAGE FlexibleInstances #-}
2+{-# LANGUAGE MultiParamTypeClasses #-}
3+{-# LANGUAGE RankNTypes #-}
4+{-# LANGUAGE TypeFamilies #-}
5+{-# LANGUAGE TypeOperators #-}
6+module Servant.Utils.Map (mapLeaves) where
7+
8+import Servant.API
9+
10+class Mappable s t a b where
11+ mapLeaves :: (forall x . a x -> b x) -> s -> t
12+
13+instance Mappable (a x) (b x) a b where
14+ mapLeaves f a = f a
15+
16+instance Mappable s t a b => Mappable (arg -> s) (arg -> t) a b where
17+ mapLeaves f s = mapLeaves f $ s
18+
19+instance (Mappable left left' a b, Mappable right right' a b) => Mappable (left :<|> right) (left' :<|> right') a b where
20+ mapLeaves f (left :<|> right) = mapLeaves f left :<|> mapLeaves f right
servant/test/Servant/Utils/MapSpec.hsnew file+27
@@ -0,0 +1,27 @@
1+module Servant.Utils.MapSpec where
2+
3+import Test.Hspec
4+
5+import Data.Functor.Identity
6+import Servant.API
7+import Servant.Utils.Map
8+spec :: Spec
9+spec = describe "Map" $ do
10+ it "maps " $ do
11+ let foo :: Bool -> Int -> String
12+ foo _ b = show b
13+
14+ bar :: () -> String -> Int -> Double
15+ bar _ _ i = fromIntegral i
16+
17+ foobar = foo :<|> bar
18+
19+ convert :: (Int -> a) -> Identity a
20+ convert f = Identity $ f 42
21+
22+ foo' :: Bool -> Identity String
23+ bar' :: () -> String -> Identity Double
24+ foo' :<|> bar' = mapLeaves convert foobar
25+
26+ foo' True `shouldBe` Identity "42"
27+ bar' () "" `shouldBe` Identity (42 :: Double)
sources.txt+2−2
@@ -1,10 +1,10 @@
11servant
2−servant-cassava
2+servant-server
33servant-client
4+servant-cassava
45servant-docs
56servant-foreign
67servant-js
7−servant-server
88servant-blaze
99servant-lucid
1010servant-mock