@@ -49,7 +49,7 @@ import Servant.API ((:<|>) (..), (:>), Capture, Delete,
49 StdMethod (..), Verb, addHeader)
49 StdMethod (..), Verb, addHeader)
50import Servant.API.Internal.Test.ComprehensiveAPI
50import Servant.API.Internal.Test.ComprehensiveAPI
51import Servant.Server (ServantErr (..), Server, err404,
51import Servant.Server (ServantErr (..), Server, err404,
52− serve, Config(EmptyConfig))
52+ serve, serveWithConfig, Config(EmptyConfig))
53import Test.Hspec (Spec, context, describe, it,
53import Test.Hspec (Spec, context, describe, it,
54 shouldBe, shouldContain)
54 shouldBe, shouldContain)
55import Test.Hspec.Wai (get, liftIO, matchHeaders,
55import Test.Hspec.Wai (get, liftIO, matchHeaders,
@@ -67,7 +67,7 @@ import Servant.Server.Internal.Config
67-- * comprehensive api test
67-- * comprehensive api test
69-- This declaration simply checks that all instances are in place.
69-- This declaration simply checks that all instances are in place.
70−_ = serve comprehensiveAPI comprehensiveApiConfig
70+_ = serveWithConfig comprehensiveAPI comprehensiveApiConfig
72comprehensiveApiConfig :: Config '[NamedConfig "foo" '[]]
72comprehensiveApiConfig :: Config '[NamedConfig "foo" '[]]
73comprehensiveApiConfig = NamedConfig EmptyConfig :. EmptyConfig
73comprehensiveApiConfig = NamedConfig EmptyConfig :. EmptyConfig
@@ -112,7 +112,7 @@ verbSpec = describe "Servant.API.Verb" $ do
112 wrongMethod m = if m == methodPatch then methodPost else methodPatch
112 wrongMethod m = if m == methodPatch then methodPost else methodPatch
113 test desc api method (status :: Int) = context desc $
113 test desc api method (status :: Int) = context desc $
115− with (return $ serve api EmptyConfig server) $ do
115+ with (return $ serve api server) $ do
117 -- HEAD and 214/215 need not return bodies
117 -- HEAD and 214/215 need not return bodies
118 unless (status `elem` [214, 215] || method == methodHead) $
118 unless (status `elem` [214, 215] || method == methodHead) $
@@ -187,7 +187,7 @@ captureServer legs = case legs of
187captureSpec :: Spec
187captureSpec :: Spec
188captureSpec = do
188captureSpec = do
189 describe "Servant.API.Capture" $ do
189 describe "Servant.API.Capture" $ do
190− with (return (serve captureApi EmptyConfig captureServer)) $ do
190+ with (return (serve captureApi captureServer)) $ do
192 it "can capture parts of the 'pathInfo'" $ do
192 it "can capture parts of the 'pathInfo'" $ do
193 response <- get "/2"
193 response <- get "/2"
@@ -198,7 +198,6 @@ captureSpec = do
199 with (return (serve
199 with (return (serve
200 (Proxy :: Proxy (Capture "captured" String :> Raw))
200 (Proxy :: Proxy (Capture "captured" String :> Raw))
202 (\ "captured" request_ respond ->
201 (\ "captured" request_ respond ->
203 respond $ responseLBS ok200 [] (cs $ show $ pathInfo request_)))) $ do
202 respond $ responseLBS ok200 [] (cs $ show $ pathInfo request_)))) $ do
204 it "strips the captured path snippet from pathInfo" $ do
203 it "strips the captured path snippet from pathInfo" $ do
@@ -232,7 +231,7 @@ queryParamSpec :: Spec
232queryParamSpec = do
231queryParamSpec = do
233 describe "Servant.API.QueryParam" $ do
232 describe "Servant.API.QueryParam" $ do
234 it "allows retrieving simple GET parameters" $
233 it "allows retrieving simple GET parameters" $
235− (flip runSession) (serve queryParamApi EmptyConfig qpServer) $ do
234+ (flip runSession) (serve queryParamApi qpServer) $ do
236 let params1 = "?name=bob"
235 let params1 = "?name=bob"
237 response1 <- Network.Wai.Test.request defaultRequest{
236 response1 <- Network.Wai.Test.request defaultRequest{
238 rawQueryString = params1,
237 rawQueryString = params1,
@@ -244,7 +243,7 @@ queryParamSpec = do
246 it "allows retrieving lists in GET parameters" $
245 it "allows retrieving lists in GET parameters" $
247− (flip runSession) (serve queryParamApi EmptyConfig qpServer) $ do
246+ (flip runSession) (serve queryParamApi qpServer) $ do
248 let params2 = "?names[]=bob&names[]=john"
247 let params2 = "?names[]=bob&names[]=john"
249 response2 <- Network.Wai.Test.request defaultRequest{
248 response2 <- Network.Wai.Test.request defaultRequest{
250 rawQueryString = params2,
249 rawQueryString = params2,
@@ -258,7 +257,7 @@ queryParamSpec = do
260 it "allows retrieving value-less GET parameters" $
259 it "allows retrieving value-less GET parameters" $
261− (flip runSession) (serve queryParamApi EmptyConfig qpServer) $ do
260+ (flip runSession) (serve queryParamApi qpServer) $ do
262 let params3 = "?capitalize"
261 let params3 = "?capitalize"
263 response3 <- Network.Wai.Test.request defaultRequest{
262 response3 <- Network.Wai.Test.request defaultRequest{
264 rawQueryString = params3,
263 rawQueryString = params3,
@@ -310,7 +309,7 @@ reqBodySpec = describe "Servant.API.ReqBody" $ do
310 mkReq method x = Test.Hspec.Wai.request method x
309 mkReq method x = Test.Hspec.Wai.request method x
311 [(hContentType, "application/json;charset=utf-8")]
310 [(hContentType, "application/json;charset=utf-8")]
313− with (return $ serve reqBodyApi EmptyConfig server) $ do
312+ with (return $ serve reqBodyApi server) $ do
315 it "passes the argument to the handler" $ do
314 it "passes the argument to the handler" $ do
316 response <- mkReq methodPost "" (encode alice)
315 response <- mkReq methodPost "" (encode alice)
@@ -343,13 +342,13 @@ headerSpec = describe "Servant.API.Header" $ do
343 expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
342 expectsString (Just x) = when (x /= "more from you") $ error "Expected more from you"
344 expectsString Nothing = error "Expected a string"
343 expectsString Nothing = error "Expected a string"
346− with (return (serve headerApi EmptyConfig expectsInt)) $ do
345+ with (return (serve headerApi expectsInt)) $ do
347 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "5")]
346 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "5")]
349 it "passes the header to the handler (Int)" $
348 it "passes the header to the handler (Int)" $
350 delete' "/" "" `shouldRespondWith` 200
349 delete' "/" "" `shouldRespondWith` 200
352− with (return (serve headerApi EmptyConfig expectsString)) $ do
351+ with (return (serve headerApi expectsString)) $ do
353 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "more from you")]
352 let delete' x = Test.Hspec.Wai.request methodDelete x [("MyHeader", "more from you")]
355 it "passes the header to the handler (String)" $
354 it "passes the header to the handler (String)" $
@@ -373,7 +372,7 @@ rawSpec :: Spec
373rawSpec = do
372rawSpec = do
374 describe "Servant.API.Raw" $ do
373 describe "Servant.API.Raw" $ do
375 it "runs applications" $ do
374 it "runs applications" $ do
376− (flip runSession) (serve rawApi EmptyConfig (rawApplication (const (42 :: Integer)))) $ do
375+ (flip runSession) (serve rawApi (rawApplication (const (42 :: Integer)))) $ do
377 response <- Network.Wai.Test.request defaultRequest{
376 response <- Network.Wai.Test.request defaultRequest{
378 pathInfo = ["foo"]
377 pathInfo = ["foo"]
@@ -381,7 +380,7 @@ rawSpec = do
381 simpleBody response `shouldBe` "42"
380 simpleBody response `shouldBe` "42"
383 it "gets the pathInfo modified" $ do
382 it "gets the pathInfo modified" $ do
384− (flip runSession) (serve rawApi EmptyConfig (rawApplication pathInfo)) $ do
383+ (flip runSession) (serve rawApi (rawApplication pathInfo)) $ do
385 response <- Network.Wai.Test.request defaultRequest{
384 response <- Network.Wai.Test.request defaultRequest{
386 pathInfo = ["foo", "bar"]
385 pathInfo = ["foo", "bar"]
@@ -415,7 +414,7 @@ alternativeServer =
415alternativeSpec :: Spec
414alternativeSpec :: Spec
416alternativeSpec = do
415alternativeSpec = do
417 describe "Servant.API.Alternative" $ do
416 describe "Servant.API.Alternative" $ do
418− with (return $ serve alternativeApi EmptyConfig alternativeServer) $ do
417+ with (return $ serve alternativeApi alternativeServer) $ do
420 it "unions endpoints" $ do
419 it "unions endpoints" $ do
421 response <- get "/foo"
420 response <- get "/foo"
@@ -450,7 +449,7 @@ responseHeadersServer = let h = return $ addHeader 5 $ addHeader "kilroy" "hi"
451responseHeadersSpec :: Spec
450responseHeadersSpec :: Spec
452responseHeadersSpec = describe "ResponseHeaders" $ do
451responseHeadersSpec = describe "ResponseHeaders" $ do
453− with (return $ serve (Proxy :: Proxy ResponseHeadersApi) EmptyConfig responseHeadersServer) $ do
452+ with (return $ serve (Proxy :: Proxy ResponseHeadersApi) responseHeadersServer) $ do
455 let methods = [methodGet, methodPost, methodPut, methodPatch]
454 let methods = [methodGet, methodPost, methodPut, methodPatch]
@@ -516,7 +515,7 @@ miscServ = versionHandler
516 hostHandler = return . show
515 hostHandler = return . show
518miscCombinatorSpec :: Spec
517miscCombinatorSpec :: Spec
519−miscCombinatorSpec = with (return $ serve miscApi EmptyConfig miscServ) $
518+miscCombinatorSpec = with (return $ serve miscApi miscServ) $
520 describe "Misc. combinators for request inspection" $ do
519 describe "Misc. combinators for request inspection" $ do
521 it "Successfully gets the HTTP version specified in the request" $
520 it "Successfully gets the HTTP version specified in the request" $
522 go "/version" "\"HTTP/1.0\""
521 go "/version" "\"HTTP/1.0\""