@@ -15,7 +15,7 @@
1515
1616module Servant.Server.Internal
1717 ( module Servant.Server.Internal
18− , module Servant.Server.Internal.Config
18+ , module Servant.Server.Internal.Context
1919 , module Servant.Server.Internal.Router
2020 , module Servant.Server.Internal.RoutingApplication
2121 , module Servant.Server.Internal.ServantErr
@@ -53,7 +53,7 @@ import Servant.API ((:<|>) (..), (:>), Capture,
5353 IsSecure(..), Header,
5454 QueryFlag, QueryParam, QueryParams,
5555 Raw, RemoteHost, ReqBody, Vault,
56− WithNamedConfig)
56+ WithNamedContext)
5757import Servant.API.ContentTypes (AcceptHeader (..),
5858 AllCTRender (..),
5959 AllCTUnrender (..),
@@ -62,16 +62,16 @@ import Servant.API.ContentTypes (AcceptHeader (..),
6262import Servant.API.ResponseHeaders (GetHeaders, Headers, getHeaders,
6363 getResponse)
6464
65−import Servant.Server.Internal.Config
65+import Servant.Server.Internal.Context
6666import Servant.Server.Internal.Router
6767import Servant.Server.Internal.RoutingApplication
6868import Servant.Server.Internal.ServantErr
6969
7070
71−class HasServer layout config where
71+class HasServer layout context where
7272 type ServerT layout (m :: * -> *) :: *
7373
74− route :: Proxy layout -> Config config -> Delayed (Server layout) -> Router
74+ route :: Proxy layout -> Context context -> Delayed (Server layout) -> Router
7575
7676type Server layout = ServerT layout (ExceptT ServantErr IO)
7777
@@ -88,12 +88,12 @@ type Server layout = ServerT layout (ExceptT ServantErr IO)
8888-- > server = listAllBooks :<|> postBook
8989-- > where listAllBooks = ...
9090-- > 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
9292
9393 type ServerT (a :<|> b) m = ServerT a m :<|> ServerT b m
9494
95− route Proxy config server = choice (route pa config ((\ (a :<|> _) -> a) <$> server))
96− (route pb config ((\ (_ :<|> b) -> b) <$> server))
95+ route Proxy context server = choice (route pa context ((\ (a :<|> _) -> a) <$> server))
96+ (route pb context ((\ (_ :<|> b) -> b) <$> server))
9797 where pa = Proxy :: Proxy a
9898 pb = Proxy :: Proxy b
9999
@@ -117,16 +117,16 @@ captured _ = parseUrlPieceMaybe
117117-- > server = getBook
118118-- > where getBook :: Text -> ExceptT ServantErr IO Book
119119-- > getBook isbn = ...
120−instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout config)
121− => HasServer (Capture capture a :> sublayout) config where
120+instance (KnownSymbol capture, FromHttpApiData a, HasServer sublayout context)
121+ => HasServer (Capture capture a :> sublayout) context where
122122
123123 type ServerT (Capture capture a :> sublayout) m =
124124 a -> ServerT sublayout m
125125
126− route Proxy config d =
126+ route Proxy context d =
127127 DynamicRouter $ \ first ->
128128 route (Proxy :: Proxy sublayout)
129− config
129+ context
130130 (addCapture d $ case captured captureProxy first of
131131 Nothing -> return $ Fail err404
132132 Just v -> return $ Route v
@@ -195,7 +195,7 @@ methodRouterHeaders method proxy status action = LeafRouter route'
195195
196196instance OVERLAPPABLE_
197197 ( 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
199199
200200 type ServerT (Verb method status ctypes a) m = m a
201201
@@ -206,7 +206,7 @@ instance OVERLAPPABLE_
206206instance OVERLAPPING_
207207 ( AllCTRender ctypes a, ReflectMethod method, KnownNat status
208208 , 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
210210
211211 type ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)
212212
@@ -234,15 +234,15 @@ instance OVERLAPPING_
234234-- > server = viewReferer
235235-- > where viewReferer :: Referer -> ExceptT ServantErr IO referer
236236-- > viewReferer referer = return referer
237−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
238− => HasServer (Header sym a :> sublayout) config where
237+instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
238+ => HasServer (Header sym a :> sublayout) context where
239239
240240 type ServerT (Header sym a :> sublayout) m =
241241 Maybe a -> ServerT sublayout m
242242
243− route Proxy config subserver = WithRequest $ \ request ->
243+ route Proxy context subserver = WithRequest $ \ request ->
244244 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)
246246 where str = fromString $ symbolVal (Proxy :: Proxy sym)
247247
248248-- | 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)
266266-- > where getBooksBy :: Maybe Text -> ExceptT ServantErr IO [Book]
267267-- > getBooksBy Nothing = ...return all books...
268268-- > getBooksBy (Just author) = ...return books by the given author...
269−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
270− => HasServer (QueryParam sym a :> sublayout) config where
269+instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
270+ => HasServer (QueryParam sym a :> sublayout) context where
271271
272272 type ServerT (QueryParam sym a :> sublayout) m =
273273 Maybe a -> ServerT sublayout m
274274
275− route Proxy config subserver = WithRequest $ \ request ->
275+ route Proxy context subserver = WithRequest $ \ request ->
276276 let querytext = parseQueryText $ rawQueryString request
277277 param =
278278 case lookup paramname querytext of
@@ -280,7 +280,7 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
280280 Just Nothing -> Nothing -- param present with no value -> Nothing
281281 Just (Just v) -> parseQueryParamMaybe v -- if present, we try to convert to
282282 -- the right type
283− in route (Proxy :: Proxy sublayout) config (passToServer subserver param)
283+ in route (Proxy :: Proxy sublayout) context (passToServer subserver param)
284284 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
285285
286286-- | 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)
302302-- > server = getBooksBy
303303-- > where getBooksBy :: [Text] -> ExceptT ServantErr IO [Book]
304304-- > getBooksBy authors = ...return all books by these authors...
305−instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
306− => HasServer (QueryParams sym a :> sublayout) config where
305+instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout context)
306+ => HasServer (QueryParams sym a :> sublayout) context where
307307
308308 type ServerT (QueryParams sym a :> sublayout) m =
309309 [a] -> ServerT sublayout m
310310
311− route Proxy config subserver = WithRequest $ \ request ->
311+ route Proxy context subserver = WithRequest $ \ request ->
312312 let querytext = parseQueryText $ rawQueryString request
313313 -- if sym is "foo", we look for query string parameters
314314 -- named "foo" or "foo[]" and call parseQueryParam on the
315315 -- corresponding values
316316 parameters = filter looksLikeParam querytext
317317 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)
319319 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
320320 looksLikeParam (name, _) = name == paramname || name == (paramname <> "[]")
321321 convert Nothing = Nothing
@@ -333,19 +333,19 @@ instance (KnownSymbol sym, FromHttpApiData a, HasServer sublayout config)
333333-- > server = getBooks
334334-- > where getBooks :: Bool -> ExceptT ServantErr IO [Book]
335335-- > getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
336−instance (KnownSymbol sym, HasServer sublayout config)
337− => HasServer (QueryFlag sym :> sublayout) config where
336+instance (KnownSymbol sym, HasServer sublayout context)
337+ => HasServer (QueryFlag sym :> sublayout) context where
338338
339339 type ServerT (QueryFlag sym :> sublayout) m =
340340 Bool -> ServerT sublayout m
341341
342− route Proxy config subserver = WithRequest $ \ request ->
342+ route Proxy context subserver = WithRequest $ \ request ->
343343 let querytext = parseQueryText $ rawQueryString request
344344 param = case lookup paramname querytext of
345345 Just Nothing -> True -- param is there, with no value
346346 Just (Just v) -> examine v -- param with a value
347347 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)
349349 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
350350 examine v | v == "true" || v == "1" || v == "" = True
351351 | otherwise = False
@@ -358,7 +358,7 @@ instance (KnownSymbol sym, HasServer sublayout config)
358358-- >
359359-- > server :: Server MyApi
360360-- > server = serveDirectory "/var/www/images"
361−instance HasServer Raw config where
361+instance HasServer Raw context where
362362
363363 type ServerT Raw m = Application
364364
@@ -390,14 +390,14 @@ instance HasServer Raw config where
390390-- > server = postBook
391391-- > where postBook :: Book -> ExceptT ServantErr IO Book
392392-- > postBook book = ...insert into your db...
393−instance ( AllCTUnrender list a, HasServer sublayout config
394− ) => HasServer (ReqBody list a :> sublayout) config where
393+instance ( AllCTUnrender list a, HasServer sublayout context
394+ ) => HasServer (ReqBody list a :> sublayout) context where
395395
396396 type ServerT (ReqBody list a :> sublayout) m =
397397 a -> ServerT sublayout m
398398
399− route Proxy config subserver = WithRequest $ \ request ->
400− route (Proxy :: Proxy sublayout) config (addBodyCheck subserver (bodyCheck request))
399+ route Proxy context subserver = WithRequest $ \ request ->
400+ route (Proxy :: Proxy sublayout) context (addBodyCheck subserver (bodyCheck request))
401401 where
402402 bodyCheck request = do
403403 -- See HTTP RFC 2616, section 7.2.1
@@ -415,40 +415,40 @@ instance ( AllCTUnrender list a, HasServer sublayout config
415415
416416-- | Make sure the incoming request starts with @"/path"@, strip it and
417417-- 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
419419
420420 type ServerT (path :> sublayout) m = ServerT sublayout m
421421
422− route Proxy config subserver = StaticRouter $
422+ route Proxy context subserver = StaticRouter $
423423 M.singleton (cs (symbolVal proxyPath))
424− (route (Proxy :: Proxy sublayout) config subserver)
424+ (route (Proxy :: Proxy sublayout) context subserver)
425425 where proxyPath = Proxy :: Proxy path
426426
427−instance HasServer api config => HasServer (RemoteHost :> api) config where
427+instance HasServer api context => HasServer (RemoteHost :> api) context where
428428 type ServerT (RemoteHost :> api) m = SockAddr -> ServerT api m
429429
430− route Proxy config subserver = WithRequest $ \req ->
431− route (Proxy :: Proxy api) config (passToServer subserver $ remoteHost req)
430+ route Proxy context subserver = WithRequest $ \req ->
431+ route (Proxy :: Proxy api) context (passToServer subserver $ remoteHost req)
432432
433−instance HasServer api config => HasServer (IsSecure :> api) config where
433+instance HasServer api context => HasServer (IsSecure :> api) context where
434434 type ServerT (IsSecure :> api) m = IsSecure -> ServerT api m
435435
436− route Proxy config subserver = WithRequest $ \req ->
437− route (Proxy :: Proxy api) config (passToServer subserver $ secure req)
436+ route Proxy context subserver = WithRequest $ \req ->
437+ route (Proxy :: Proxy api) context (passToServer subserver $ secure req)
438438
439439 where secure req = if isSecure req then Secure else NotSecure
440440
441−instance HasServer api config => HasServer (Vault :> api) config where
441+instance HasServer api context => HasServer (Vault :> api) context where
442442 type ServerT (Vault :> api) m = Vault -> ServerT api m
443443
444− route Proxy config subserver = WithRequest $ \req ->
445− route (Proxy :: Proxy api) config (passToServer subserver $ vault req)
444+ route Proxy context subserver = WithRequest $ \req ->
445+ route (Proxy :: Proxy api) context (passToServer subserver $ vault req)
446446
447−instance HasServer api config => HasServer (HttpVersion :> api) config where
447+instance HasServer api context => HasServer (HttpVersion :> api) context where
448448 type ServerT (HttpVersion :> api) m = HttpVersion -> ServerT api m
449449
450− route Proxy config subserver = WithRequest $ \req ->
451− route (Proxy :: Proxy api) config (passToServer subserver $ httpVersion req)
450+ route Proxy context subserver = WithRequest $ \req ->
451+ route (Proxy :: Proxy api) context (passToServer subserver $ httpVersion req)
452452
453453pathIsEmpty :: Request -> Bool
454454pathIsEmpty = go . pathInfo
@@ -459,19 +459,19 @@ pathIsEmpty = go . pathInfo
459459ct_wildcard :: B.ByteString
460460ct_wildcard = "*" <> "/" <> "*" -- Because CPP
461461
462−-- * configs
462+-- * contexts
463463
464−instance (HasConfigEntry config (NamedConfig name subConfig), HasServer subApi subConfig)
465− => HasServer (WithNamedConfig name subConfig subApi) config where
464+instance (HasContextEntry context (NamedContext name subContext), HasServer subApi subContext)
465+ => HasServer (WithNamedContext name subContext subApi) context where
466466
467− type ServerT (WithNamedConfig name subConfig subApi) m =
467+ type ServerT (WithNamedContext name subContext subApi) m =
468468 ServerT subApi m
469469
470− route Proxy config delayed =
471− route subProxy subConfig delayed
470+ route Proxy context delayed =
471+ route subProxy subContext delayed
472472 where
473473 subProxy :: Proxy subApi
474474 subProxy = Proxy
475475
476− subConfig :: Config subConfig
477− subConfig = descendIntoNamedConfig (Proxy :: Proxy name) config
476+ subContext :: Context subContext
477+ subContext = descendIntoNamedContext (Proxy :: Proxy name) context