on master help sign in
basic-auth: config -> context
commit546adc391a2699063d76f2e5f5b18498f1415e85 authoraaron levin <aaron.levin@soundcloud.com> dateTue 8 Mar 2016, 23:28 (11 years ago) parent1e703be
5 files changed+23−23
servant-client/test/Servant/ClientSpec.hs+3−3 servant-examples/basic-auth/basic-auth.hs+8−8 servant-server/src/Servant/Server/Internal.hs+7−7 servant-server/test/Servant/Server/ErrorSpec.hs+4−4 servant-server/test/Servant/ServerSpec.hs+1−1
servant-client/test/Servant/ClientSpec.hs+3−3
@@ -166,11 +166,11 @@ basicAuthHandler =
166166 else return Unauthorized
167167 in BasicAuthCheck check
168168
169−serverConfig :: Config '[ BasicAuthCheck () ]
170−serverConfig = basicAuthHandler :. EmptyConfig
169+serverContext :: Context '[ BasicAuthCheck () ]
170+serverContext = basicAuthHandler :. EmptyContext
171171
172172basicAuthServer :: Application
173−basicAuthServer = serveWithConfig basicAuthAPI serverConfig (const (return alice))
173+basicAuthServer = serveWithContext basicAuthAPI serverContext (const (return alice))
174174
175175{-# NOINLINE manager #-}
176176manager :: C.Manager
servant-examples/basic-auth/basic-auth.hs+8−8
@@ -18,8 +18,8 @@ import Servant.Server (BasicAuthCheck (BasicAuthCheck),
1818 BasicAuthResult( Authorized
1919 , Unauthorized
2020 ),
21− Config ((:.), EmptyConfig), Server,
22− serveWithConfig)
21+ Context ((:.), EmptyContext), Server,
22+ serveWithContext)
2323
2424-- | let's define some types that our API returns.
2525
@@ -62,12 +62,12 @@ authCheck =
6262 else return Unauthorized
6363 in BasicAuthCheck check
6464
65−-- | We need to supply our handlers with the right configuration. In this case,
66−-- Basic Authentication requires a Config Entry with the 'BasicAuthCheck' value
67−-- tagged with "foo-tag" This config is then supplied to 'server' and threaded
65+-- | We need to supply our handlers with the right Context. In this case,
66+-- Basic Authentication requires a Context Entry with the 'BasicAuthCheck' value
67+-- tagged with "foo-tag" This context is then supplied to 'server' and threaded
6868-- to the BasicAuth HasServer handlers.
69−serverConfig :: Config (BasicAuthCheck User ': '[])
70−serverConfig = authCheck :. EmptyConfig
69+serverContext :: Context (BasicAuthCheck User ': '[])
70+serverContext = authCheck :. EmptyContext
7171
7272-- | an implementation of our server. Here is where we pass all the handlers to our endpoints.
7373-- In particular, for the BasicAuth protected handler, we need to supply a function
@@ -80,7 +80,7 @@ server =
8080
8181-- | hello, server!
8282main :: IO ()
83−main = run 8080 (serveWithConfig api serverConfig server)
83+main = run 8080 (serveWithContext api serverContext server)
8484
8585{- Sample session
8686
servant-server/src/Servant/Server/Internal.hs+7−7
@@ -457,19 +457,19 @@ instance HasServer api context => HasServer (HttpVersion :> api) context where
457457
458458-- | Basic Authentication
459459instance ( KnownSymbol realm
460− , HasServer api config
461− , HasConfigEntry config (BasicAuthCheck usr)
460+ , HasServer api context
461+ , HasContextEntry context (BasicAuthCheck usr)
462462 )
463− => HasServer (BasicAuth realm usr :> api) config where
463+ => HasServer (BasicAuth realm usr :> api) context where
464464
465465 type ServerT (BasicAuth realm usr :> api) m = usr -> ServerT api m
466466
467− route Proxy config subserver = WithRequest $ \ request ->
468− route (Proxy :: Proxy api) config (subserver `addAuthCheck` authCheck request)
467+ route Proxy context subserver = WithRequest $ \ request ->
468+ route (Proxy :: Proxy api) context (subserver `addAuthCheck` authCheck request)
469469 where
470470 realm = BC8.pack $ symbolVal (Proxy :: Proxy realm)
471− basicAuthConfig = getConfigEntry config
472− authCheck req = runBasicAuth req realm basicAuthConfig
471+ basicAuthContext = getContextEntry context
472+ authCheck req = runBasicAuth req realm basicAuthContext
473473
474474-- * helpers
475475
servant-server/test/Servant/Server/ErrorSpec.hs+4−4
@@ -56,8 +56,8 @@ errorOrderServer = \_ _ _ -> throwE err402
5656errorOrderSpec :: Spec
5757errorOrderSpec =
5858 describe "HTTP error order" $
59− with (return $ serveWithConfig errorOrderApi
60− (errorOrderAuthCheck :. EmptyConfig)
59+ with (return $ serveWithContext errorOrderApi
60+ (errorOrderAuthCheck :. EmptyContext)
6161 errorOrderServer
6262 ) $ do
6363 let badContentType = (hContentType, "text/plain")
@@ -183,8 +183,8 @@ errorRetryServer
183183errorRetrySpec :: Spec
184184errorRetrySpec =
185185 describe "Handler search" $
186− with (return $ serveWithConfig errorRetryApi
187− (errorOrderAuthCheck :. EmptyConfig)
186+ with (return $ serveWithContext errorRetryApi
187+ (errorOrderAuthCheck :. EmptyContext)
188188 errorRetryServer
189189 ) $ do
190190
servant-server/test/Servant/ServerSpec.hs+1−1
@@ -65,7 +65,7 @@ import Servant.Server.Internal.Router
6565 (tweakResponse, runRouter,
6666 Router, Router'(LeafRouter))
6767import Servant.Server.Internal.Context
68− (Context(..), NamedContext(..))
68+ (NamedContext(..))
6969
7070-- * comprehensive api test
7171