@@ -15,7 +15,7 @@
16module Servant.Server.Internal
16module Servant.Server.Internal
17 ( module Servant.Server.Internal
17 ( module Servant.Server.Internal
18− , module Servant.Server.Internal.Config
18+ , module Servant.Server.Internal.Context
19 , module Servant.Server.Internal.Router
19 , module Servant.Server.Internal.Router
20 , module Servant.Server.Internal.RoutingApplication
20 , module Servant.Server.Internal.RoutingApplication
21 , module Servant.Server.Internal.ServantErr
21 , module Servant.Server.Internal.ServantErr
@@ -53,7 +53,7 @@ import Servant.API ((:<|>) (..), (:>), Capture,
53 IsSecure(..), Header,
53 IsSecure(..), Header,
54 QueryFlag, QueryParam, QueryParams,
54 QueryFlag, QueryParam, QueryParams,
55 Raw, RemoteHost, ReqBody, Vault,
55 Raw, RemoteHost, ReqBody, Vault,
56− WithNamedConfig)
56+ WithNamedContext)
57import Servant.API.ContentTypes (AcceptHeader (..),
57import Servant.API.ContentTypes (AcceptHeader (..),
58 AllCTRender (..),
58 AllCTRender (..),
59 AllCTUnrender (..),
59 AllCTUnrender (..),
@@ -62,16 +62,16 @@ import Servant.API.ContentTypes (AcceptHeader (..),
62import Servant.API.ResponseHeaders (GetHeaders, Headers, getHeaders,
62import Servant.API.ResponseHeaders (GetHeaders, Headers, getHeaders,
63 getResponse)
63 getResponse)
65−import Servant.Server.Internal.Config
65+import Servant.Server.Internal.Context
66import Servant.Server.Internal.Router
66import Servant.Server.Internal.Router
67import Servant.Server.Internal.RoutingApplication
67import Servant.Server.Internal.RoutingApplication
68import Servant.Server.Internal.ServantErr
68import Servant.Server.Internal.ServantErr
71−class HasServer layout config where
71+class HasServer layout context where
72 type ServerT layout (m :: * -> *) :: *
72 type ServerT layout (m :: * -> *) :: *
74− route :: Proxy layout -> Config config -> Delayed (Server layout) -> Router
74+ route :: Proxy layout -> Context context -> Delayed (Server layout) -> Router
76type Server layout = ServerT layout (ExceptT ServantErr IO)
76type Server layout = ServerT layout (ExceptT ServantErr IO)
@@ -88,12 +88,12 @@ type Server layout = ServerT layout (ExceptT ServantErr IO)
88-- > server = listAllBooks :<|> postBook
88-- > server = listAllBooks :<|> postBook
89-- > where listAllBooks = ...
89-- > where listAllBooks = ...
90-- > postBook book = ...
90-- > postBook book = ...
91−instance (HasServer a config, HasServer b config) => HasServer (a :<|> b) config where
91+instance (HasServer a context, HasServer b context) => HasServer (a :<|> b) context where
93 type ServerT (a :<|> b) m = ServerT a m :<|> ServerT b m
93 type ServerT (a :<|> b) m = ServerT a m :<|> ServerT b m
95− route Proxy config server = choice (route pa config ((\ (a :<|> _) -> a) <$> server))
95+ route Proxy context server = choice (route pa context ((\ (a :<|> _) -> a) <$> server))
96− (route pb config ((\ (_ :<|> b) -> b) <$> server))
96+ (route pb context ((\ (_ :<|> b) -> b) <$> server))
97 where pa = Proxy :: Proxy a
97 where pa = Proxy :: Proxy a
98 pb = Proxy :: Proxy b
98 pb = Proxy :: Proxy b
@@ -117,16 +117,16 @@ captured _ = parseUrlPieceMaybe
117-- > server = getBook
117-- > server = getBook
118-- > where getBook :: Text -> ExceptT ServantErr IO Book
118-- > where getBook :: Text -> ExceptT ServantErr IO Book
119-- > getBook isbn = ...
119-- > getBook isbn = ...
120−instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout config)
120+instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout context)
121− => HasServer (Capture capture a :> sublayout) config where
121+ => HasServer (Capture capture a :> sublayout) context where
123 type ServerT (Capture capture a :> sublayout) m =
123 type ServerT (Capture capture a :> sublayout) m =
124 a -> ServerT sublayout m
124 a -> ServerT sublayout m
126− route Proxy config d =
126+ route Proxy context d =
127 DynamicRouter $ \ first ->
127 DynamicRouter $ \ first ->
128 route (Proxy :: Proxy sublayout)
128 route (Proxy :: Proxy sublayout)
130 (addCapture d $ case captured captureProxy first of
130 (addCapture d $ case captured captureProxy first of
131 Nothing -> return $ Fail err404
131 Nothing -> return $ Fail err404
132 Just v -> return $ Route v
132 Just v -> return $ Route v
@@ -195,7 +195,7 @@ methodRouterHeaders method proxy status action = LeafRouter route'
196instance OVERLAPPABLE_
196instance OVERLAPPABLE_
197 ( AllCTRender ctypes a, ReflectMethod method, KnownNat status
197 ( AllCTRender ctypes a, ReflectMethod method, KnownNat status
198− ) => HasServer (Verb method status ctypes a) config where
198+ ) => HasServer (Verb method status ctypes a) context where
200 type ServerT (Verb method status ctypes a) m = m a
200 type ServerT (Verb method status ctypes a) m = m a
@@ -206,7 +206,7 @@ instance OVERLAPPABLE_
206instance OVERLAPPING_
206instance OVERLAPPING_
207 ( AllCTRender ctypes a, ReflectMethod method, KnownNat status
207 ( AllCTRender ctypes a, ReflectMethod method, KnownNat status
208 , GetHeaders (Headers h a)
208 , GetHeaders (Headers h a)
209− ) => HasServer (Verb method status ctypes (Headers h a)) config where
209+ ) => HasServer (Verb method status ctypes (Headers h a)) context where
211 type ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)
211 type ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)
@@ -234,15 +234,15 @@ instance OVERLAPPING_
234-- > server = viewReferer
234-- > server = viewReferer
235-- > where viewReferer :: Referer -> ExceptT ServantErr IO referer
235-- > where viewReferer :: Referer -> ExceptT ServantErr IO referer
236-- > viewReferer referer = return referer
236-- > viewReferer referer = return referer
237−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
237+instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
238− => HasServer (Header sym a :> sublayout) config where
238+ => HasServer (Header sym a :> sublayout) context where
240 type ServerT (Header sym a :> sublayout) m =
240 type ServerT (Header sym a :> sublayout) m =
241 Maybe a -> ServerT sublayout m
241 Maybe a -> ServerT sublayout m
243− route Proxy config subserver = WithRequest $ \ request ->
243+ route Proxy context subserver = WithRequest $ \ request ->
244 let mheader = parseHeaderMaybe =<< lookup str (requestHeaders request)
244 let mheader = parseHeaderMaybe =<< lookup str (requestHeaders request)
245− in route (Proxy :: Proxy sublayout) config (passToServer subserver mheader)
245+ in route (Proxy :: Proxy sublayout) context (passToServer subserver mheader)
246 where str = fromString $ symbolVal (Proxy :: Proxy sym)
246 where str = fromString $ symbolVal (Proxy :: Proxy sym)
248-- | If you use @'QueryParam' "author" Text@ in one of the endpoints for your API,
248-- | If you use @'QueryParam' "author" Text@ in one of the endpoints for your API,
@@ -266,13 +266,13 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
266-- > where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book]
266-- > where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book]
267-- > getBooksBy Nothing = ...return all books...
267-- > getBooksBy Nothing = ...return all books...
268-- > getBooksBy (Just author) = ...return books by the given author...
268-- > getBooksBy (Just author) = ...return books by the given author...
269−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
269+instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
270− => HasServer (QueryParam sym a :> sublayout) config where
270+ => HasServer (QueryParam sym a :> sublayout) context where
272 type ServerT (QueryParam sym a :> sublayout) m =
272 type ServerT (QueryParam sym a :> sublayout) m =
273 Maybe a -> ServerT sublayout m
273 Maybe a -> ServerT sublayout m
275− route Proxy config subserver = WithRequest $ \ request ->
275+ route Proxy context subserver = WithRequest $ \ request ->
276 let querytext = parseQueryText $ rawQueryString request
276 let querytext = parseQueryText $ rawQueryString request
278 case lookup paramname querytext of
278 case lookup paramname querytext of
@@ -280,7 +280,7 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
280 Just Nothing -> Nothing -- param present with no value -> Nothing
280 Just Nothing -> Nothing -- param present with no value -> Nothing
281 Just (Just v) -> parseQueryParamMaybe v -- if present, we try to convert to
281 Just (Just v) -> parseQueryParamMaybe v -- if present, we try to convert to
282 -- the right type
282 -- the right type
283− in route (Proxy :: Proxy sublayout) config (passToServer subserver param)
283+ in route (Proxy :: Proxy sublayout) context (passToServer subserver param)
284 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
284 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
286-- | If you use @'QueryParams' "authors" Text@ in one of the endpoints for your API,
286-- | If you use @'QueryParams' "authors" Text@ in one of the endpoints for your API,
@@ -302,20 +302,20 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
302-- > server = getBooksBy
302-- > server = getBooksBy
303-- > where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book]
303-- > where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book]
304-- > getBooksBy authors = ...return all books by these authors...
304-- > getBooksBy authors = ...return all books by these authors...
305−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
305+instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
306− => HasServer (QueryParams sym a :> sublayout) config where
306+ => HasServer (QueryParams sym a :> sublayout) context where
308 type ServerT (QueryParams sym a :> sublayout) m =
308 type ServerT (QueryParams sym a :> sublayout) m =
309 [a] -> ServerT sublayout m
309 [a] -> ServerT sublayout m
311− route Proxy config subserver = WithRequest $ \ request ->
311+ route Proxy context subserver = WithRequest $ \ request ->
312 let querytext = parseQueryText $ rawQueryString request
312 let querytext = parseQueryText $ rawQueryString request
313 -- if sym is "foo", we look for query string parameters
313 -- if sym is "foo", we look for query string parameters
314 -- named "foo" or "foo[]" and call parseQueryParam on the
314 -- named "foo" or "foo[]" and call parseQueryParam on the
315 -- corresponding values
315 -- corresponding values
316 parameters = filter looksLikeParam querytext
316 parameters = filter looksLikeParam querytext
317 values = mapMaybe (convert . snd) parameters
317 values = mapMaybe (convert . snd) parameters
318− in route (Proxy :: Proxy sublayout) config (passToServer subserver values)
318+ in route (Proxy :: Proxy sublayout) context (passToServer subserver values)
319 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
319 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
320 looksLikeParam (name, _) = name == paramname || name == (paramname <> "[]")
320 looksLikeParam (name, _) = name == paramname || name == (paramname <> "[]")
321 convert Nothing = Nothing
321 convert Nothing = Nothing
@@ -333,19 +333,19 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
333-- > server = getBooks
333-- > server = getBooks
334-- > where getBooks :: Bool -> ExceptT ServantErr IO [Book]
334-- > where getBooks :: Bool -> ExceptT ServantErr IO [Book]
335-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
335-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
336−instance (KnownSymbol sym, HasServer sublayout config)
336+instance (KnownSymbol sym, HasServer sublayout context)
337− => HasServer (QueryFlag sym :> sublayout) config where
337+ => HasServer (QueryFlag sym :> sublayout) context where
339 type ServerT (QueryFlag sym :> sublayout) m =
339 type ServerT (QueryFlag sym :> sublayout) m =
340 Bool -> ServerT sublayout m
340 Bool -> ServerT sublayout m
342− route Proxy config subserver = WithRequest $ \ request ->
342+ route Proxy context subserver = WithRequest $ \ request ->
343 let querytext = parseQueryText $ rawQueryString request
343 let querytext = parseQueryText $ rawQueryString request
344 param = case lookup paramname querytext of
344 param = case lookup paramname querytext of
345 Just Nothing -> True -- param is there, with no value
345 Just Nothing -> True -- param is there, with no value
346 Just (Just v) -> examine v -- param with a value
346 Just (Just v) -> examine v -- param with a value
347 Nothing -> False -- param not in the query string
347 Nothing -> False -- param not in the query string
348− in route (Proxy :: Proxy sublayout) config (passToServer subserver param)
348+ in route (Proxy :: Proxy sublayout) context (passToServer subserver param)
349 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
349 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
350 examine v | v == "true" || v == "1" || v == "" = True
350 examine v | v == "true" || v == "1" || v == "" = True
351 | otherwise = False
351 | otherwise = False
@@ -358,7 +358,7 @@ instance (KnownSymbol sym, HasServer sublayout config)
359-- > server :: Server MyApi
359-- > server :: Server MyApi
360-- > server = serveDirectory "/var/www/images"
360-- > server = serveDirectory "/var/www/images"
361−instance HasServer Raw config where
361+instance HasServer Raw context where
363 type ServerT Raw m = Application
363 type ServerT Raw m = Application
@@ -390,14 +390,14 @@ instance HasServer Raw config where
390-- > server = postBook
390-- > server = postBook
391-- > where postBook :: Book -> ExceptT ServantErr IO Book
391-- > where postBook :: Book -> ExceptT ServantErr IO Book
392-- > postBook book = ...insert into your db...
392-- > postBook book = ...insert into your db...
393−instance ( AllCTUnrender list a, HasServer sublayout config
393+instance ( AllCTUnrender list a, HasServer sublayout context
394− ) => HasServer (ReqBody list a :> sublayout) config where
394+ ) => HasServer (ReqBody list a :> sublayout) context where
396 type ServerT (ReqBody list a :> sublayout) m =
396 type ServerT (ReqBody list a :> sublayout) m =
397 a -> ServerT sublayout m
397 a -> ServerT sublayout m
399− route Proxy config subserver = WithRequest $ \ request ->
399+ route Proxy context subserver = WithRequest $ \ request ->
400− route (Proxy :: Proxy sublayout) config (addBodyCheck subserver (bodyCheck request))
400+ route (Proxy :: Proxy sublayout) context (addBodyCheck subserver (bodyCheck request))
402 bodyCheck request = do
402 bodyCheck request = do
403 -- See HTTP RFC 2616, section 7.2.1
403 -- See HTTP RFC 2616, section 7.2.1
@@ -415,40 +415,40 @@ instance ( AllCTUnrender list a, HasServer sublayout config
416-- | Make sure the incoming request starts with @"/path"@, strip it and
416-- | Make sure the incoming request starts with @"/path"@, strip it and
417-- pass the rest of the request path to @sublayout@.
417-- pass the rest of the request path to @sublayout@.
418−instance (KnownSymbol path, HasServer sublayout config) => HasServer (path :> sublayout) config where
418+instance (KnownSymbol path, HasServer sublayout context) => HasServer (path :> sublayout) context where
420 type ServerT (path :> sublayout) m = ServerT sublayout m
420 type ServerT (path :> sublayout) m = ServerT sublayout m
422− route Proxy config subserver = StaticRouter $
422+ route Proxy context subserver = StaticRouter $
423 M.singleton (cs (symbolVal proxyPath))
423 M.singleton (cs (symbolVal proxyPath))
424− (route (Proxy :: Proxy sublayout) config subserver)
424+ (route (Proxy :: Proxy sublayout) context subserver)
425 where proxyPath = Proxy :: Proxy path
425 where proxyPath = Proxy :: Proxy path
427−instance HasServer api config => HasServer (RemoteHost :> api) config where
427+instance HasServer api context => HasServer (RemoteHost :> api) context where
428 type ServerT (RemoteHost :> api) m = SockAddr -> ServerT api m
428 type ServerT (RemoteHost :> api) m = SockAddr -> ServerT api m
430− route Proxy config subserver = WithRequest $ \req ->
430+ route Proxy context subserver = WithRequest $ \req ->
431− route (Proxy :: Proxy api) config (passToServer subserver $ remoteHost req)
431+ route (Proxy :: Proxy api) context (passToServer subserver $ remoteHost req)
433−instance HasServer api config => HasServer (IsSecure :> api) config where
433+instance HasServer api context => HasServer (IsSecure :> api) context where
434 type ServerT (IsSecure :> api) m = IsSecure -> ServerT api m
434 type ServerT (IsSecure :> api) m = IsSecure -> ServerT api m
436− route Proxy config subserver = WithRequest $ \req ->
436+ route Proxy context subserver = WithRequest $ \req ->
437− route (Proxy :: Proxy api) config (passToServer subserver $ secure req)
437+ route (Proxy :: Proxy api) context (passToServer subserver $ secure req)
439 where secure req = if isSecure req then Secure else NotSecure
439 where secure req = if isSecure req then Secure else NotSecure
441−instance HasServer api config => HasServer (Vault :> api) config where
441+instance HasServer api context => HasServer (Vault :> api) context where
442 type ServerT (Vault :> api) m = Vault -> ServerT api m
442 type ServerT (Vault :> api) m = Vault -> ServerT api m
444− route Proxy config subserver = WithRequest $ \req ->
444+ route Proxy context subserver = WithRequest $ \req ->
445− route (Proxy :: Proxy api) config (passToServer subserver $ vault req)
445+ route (Proxy :: Proxy api) context (passToServer subserver $ vault req)
447−instance HasServer api config => HasServer (HttpVersion :> api) config where
447+instance HasServer api context => HasServer (HttpVersion :> api) context where
448 type ServerT (HttpVersion :> api) m = HttpVersion -> ServerT api m
448 type ServerT (HttpVersion :> api) m = HttpVersion -> ServerT api m
450− route Proxy config subserver = WithRequest $ \req ->
450+ route Proxy context subserver = WithRequest $ \req ->
451− route (Proxy :: Proxy api) config (passToServer subserver $ httpVersion req)
451+ route (Proxy :: Proxy api) context (passToServer subserver $ httpVersion req)
453pathIsEmpty :: Request -> Bool
453pathIsEmpty :: Request -> Bool
454pathIsEmpty = go . pathInfo
454pathIsEmpty = go . pathInfo
@@ -459,19 +459,19 @@ pathIsEmpty = go . pathInfo
459ct_wildcard :: B.ByteString
459ct_wildcard :: B.ByteString
460ct_wildcard = "*" <> "/" <> "*" -- Because CPP
460ct_wildcard = "*" <> "/" <> "*" -- Because CPP
462−-- * configs
462+-- * contexts
464−instance (HasConfigEntry config (NamedConfig name subConfig), HasServer subApi subConfig)
464+instance (HasContextEntry context (NamedContext name subContext), HasServer subApi subContext)
465− => HasServer (WithNamedConfig name subConfig subApi) config where
465+ => HasServer (WithNamedContext name subContext subApi) context where
467− type ServerT (WithNamedConfig name subConfig subApi) m =
467+ type ServerT (WithNamedContext name subContext subApi) m =
468 ServerT subApi m
468 ServerT subApi m
470− route Proxy config delayed =
470+ route Proxy context delayed =
471− route subProxy subConfig delayed
471+ route subProxy subContext delayed
473 subProxy :: Proxy subApi
473 subProxy :: Proxy subApi
474 subProxy = Proxy
474 subProxy = Proxy
476− subConfig :: Config subConfig
476+ subContext :: Context subContext
477− subConfig = descendIntoNamedConfig (Proxy :: Proxy name) config
477+ subContext = descendIntoNamedContext (Proxy :: Proxy name) context