on master help sign in
7.8 routing fixes, -Wall, cleanup, changelog.
9c12b78Julian K. Arni
servant-server/CHANGELOG.md+1−3
@@ -7,9 +7,7 @@ HEAD
7* Remove matrix params.
7* Remove matrix params.
8* Remove `RouteMismatch`.
8* Remove `RouteMismatch`.
9* Redefined constructors of `RouteResult`.
9* Redefined constructors of `RouteResult`.
10−* Add `failFatallyWith`.
10+* Added `Delayed` and related functions (`addMethodCheck`, `addAcceptCheck`, `addBodyCheck`, `runDelayed`)
11−* Make all (framework-generated) HTTP errors except 404 and 405 not try other
12− handlers.
13
11
140.4.1
120.4.1
15-----
13-----
servant-server/servant-server.cabal+1
@@ -95,6 +95,7 @@ test-suite spec
95 Servant.Server.Internal.EnterSpec
95 Servant.Server.Internal.EnterSpec
96 Servant.ServerSpec
96 Servant.ServerSpec
97 Servant.Utils.StaticFilesSpec
97 Servant.Utils.StaticFilesSpec
98+ Servant.Server.ErrorSpec
98 build-depends:
99 build-depends:
99 base == 4.*
100 base == 4.*
100 , aeson
101 , aeson
servant-server/src/Servant/Server/Internal/Router.hs−1
@@ -6,7 +6,6 @@ import Data.Map (Map)
6import qualified Data.Map as M
6import qualified Data.Map as M
7import Data.Text (Text)
7import Data.Text (Text)
8import Network.Wai (Request, Response, pathInfo)
8import Network.Wai (Request, Response, pathInfo)
9−import Servant.Server.Internal.PathInfo
10import Servant.Server.Internal.RoutingApplication
9import Servant.Server.Internal.RoutingApplication
11import Servant.Server.Internal.ServantErr
10import Servant.Server.Internal.ServantErr
12
11
servant-server/src/Servant/Server/Internal/RoutingApplication.hs+3−6
@@ -8,9 +8,7 @@
8module Servant.Server.Internal.RoutingApplication where
8module Servant.Server.Internal.RoutingApplication where
9
9
10#if !MIN_VERSION_base(4,8,0)
10#if !MIN_VERSION_base(4,8,0)
11−import Control.Applicative (Applicative, (<$>))
11+import Control.Applicative ((<$>))
12−import Data.Monoid (Monoid, mappend, mempty,
13− (<>))
14#endif
12#endif
15import Control.Monad.Trans.Except (ExceptT, runExceptT)
13import Control.Monad.Trans.Except (ExceptT, runExceptT)
16import qualified Data.ByteString as B
14import qualified Data.ByteString as B
@@ -69,8 +67,6 @@ toApplication ra request respond = do
69 routingRespond (FailFatal err) = respond $ responseServantErr err
67 routingRespond (FailFatal err) = respond $ responseServantErr err
70 routingRespond (Route v) = respond v
68 routingRespond (Route v) = respond v
71
69
72−-- TODO: The above may not be quite right yet.
73−--
74-- We currently mix up the order in which we perform checks
70-- We currently mix up the order in which we perform checks
75-- and the priority with which errors are reported.
71-- and the priority with which errors are reported.
76--
72--
@@ -162,7 +158,8 @@ data Delayed :: * -> * where
162 -> (a -> b -> RouteResult c)
158 -> (a -> b -> RouteResult c)
163 -> Delayed c
159 -> Delayed c
164
160
165−deriving instance Functor Delayed
161+instance Functor Delayed where
162+ fmap f (Delayed a b c g) = Delayed a b c ((fmap.fmap.fmap) f g)
166
163
167-- | Add a capture to the end of the capture block.
164-- | Add a capture to the end of the capture block.
168addCapture :: Delayed (a -> b)
165addCapture :: Delayed (a -> b)
servant-server/test/Servant/Server/ErrorSpec.hs+1−21
@@ -18,24 +18,6 @@ import Test.Hspec.Wai
18
18
19import Servant
19import Servant
20
20
21−
22−-- The semantics of routing and handling requests should be as follows:
23−--
24−-- 1) Check whether one or more endpoints have the right path. Otherwise
25−-- return 404.
26−-- 2) Check whether the one of those have the right method. Otherwise return
27−-- 405. If so, pick the first. We've now committed to calling at most one
28−-- handler.
29−-- 3) Check whether the Content-Type is known. Otherwise return 415.
30−-- 4) Check whether that one deserializes the body. Otherwise return 400. If
31−-- there was no Content-Type, try the first one of the API content-type list.
32−-- 5) Check whether the request is authorized. Otherwise return a 401.
33−-- 6) Check whether the request is forbidden. If so return 403.
34−-- 7) Check whether the request has a known Accept. Otherwise return 406.
35−-- 8) Check whether Accept-Language, Accept-Charset and Accept-Encoding
36−-- exist and match. We can follow the webmachine order here.
37−-- 9) Call the handler. Whatever it returns, we return.
38−
39spec :: Spec
21spec :: Spec
40spec = describe "HTTP Errors" $ do
22spec = describe "HTTP Errors" $ do
41 errorOrderSpec
23 errorOrderSpec
@@ -174,9 +156,7 @@ errorRetrySpec :: Spec
174errorRetrySpec = describe "Handler search"
156errorRetrySpec = describe "Handler search"
175 $ with (return $ serve errorRetryApi errorRetryServer) $ do
157 $ with (return $ serve errorRetryApi errorRetryServer) $ do
176
158
177− let plainCT = (hContentType, "text/plain")
178− plainAccept = (hAccept, "text/plain")
179− jsonCT = (hContentType, "application/json")
159+ let jsonCT = (hContentType, "application/json")
180 jsonAccept = (hAccept, "application/json")
160 jsonAccept = (hAccept, "application/json")
181 jsonBody = encode (1797 :: Int)
161 jsonBody = encode (1797 :: Int)
182
162
servant-server/test/Servant/ServerSpec.hs+4−17
@@ -33,21 +33,6 @@ import Network.Wai (Application, Request, pathInfo,
33import Network.Wai.Internal (Response(ResponseBuilder))
33import Network.Wai.Internal (Response(ResponseBuilder))
34import Network.Wai.Test (defaultRequest, request,
34import Network.Wai.Test (defaultRequest, request,
35 runSession, simpleBody)
35 runSession, simpleBody)
36−import Servant.API ((:<|>) (..), (:>), Capture, Delete,
37− Get, Header (..), Headers,
38− HttpVersion, IsSecure (..), JSON,
39− MatrixFlag, MatrixParam,
40− MatrixParams, Patch, PlainText,
41− Post, Put, QueryFlag, QueryParam,
42− QueryParams, Raw, RemoteHost,
43− ReqBody, addHeader)
44−import Servant.Server (ServantErr (..), Server, err404,
45− serve)
46−import Test.Hspec (Spec, describe, it, shouldBe)
47−import Test.Hspec.Wai (get, liftIO, matchHeaders,
48− matchStatus, post, request,
49− shouldRespondWith, with, (<:>))
50−<<<<<<< HEAD
51import Servant.API ((:<|>) (..), (:>), Capture, Delete,
36import Servant.API ((:<|>) (..), (:>), Capture, Delete,
52 Get, Header (..), Headers,
37 Get, Header (..), Headers,
53 HttpVersion, IsSecure (..), JSON,
38 HttpVersion, IsSecure (..), JSON,
@@ -56,9 +41,11 @@ import Servant.API ((:<|>) (..), (:>), Capture, Delete,
56 Raw, RemoteHost, ReqBody,
41 Raw, RemoteHost, ReqBody,
57 addHeader)
42 addHeader)
58import Servant.Server (Server, serve, ServantErr(..), err404)
43import Servant.Server (Server, serve, ServantErr(..), err404)
59−=======
44+import Test.Hspec (Spec, describe, it, shouldBe)
45+import Test.Hspec.Wai (get, liftIO, matchHeaders,
46+ matchStatus, post, request,
47+ shouldRespondWith, with, (<:>))
60import Servant.Server.Internal.RoutingApplication (toApplication, RouteResult(..))
48import Servant.Server.Internal.RoutingApplication (toApplication, RouteResult(..))
61−>>>>>>> Rebase cleanup and test fixes.
62import Servant.Server.Internal.Router
49import Servant.Server.Internal.Router
63 (tweakResponse, runRouter,
50 (tweakResponse, runRouter,
64 Router, Router'(LeafRouter))
51 Router, Router'(LeafRouter))