git.iko.soy/typeable/servant
on master help sign in
7.8 routing fixes, -Wall, cleanup, changelog.
commit9c12b7839b6d7adc6bf1fc59c422797da0f5c5a0 authorJulian K. Arni <jkarni@gmail.com> dateTue 13 Oct 2015, 20:29 (11 years ago) parent1398d1f
6 files changed+10−48
servant-server/CHANGELOG.md+1−3 servant-server/servant-server.cabal+1 servant-server/src/Servant/Server/Internal/Router.hs−1 servant-server/src/Servant/Server/Internal/RoutingApplication.hs+3−6 servant-server/test/Servant/Server/ErrorSpec.hs+1−21 servant-server/test/Servant/ServerSpec.hs+4−17
servant-server/CHANGELOG.md+1−3
@@ -7,9 +7,7 @@ HEAD
77* Remove matrix params.
88* Remove `RouteMismatch`.
99* Redefined constructors of `RouteResult`.
10−* Add `failFatallyWith`.
11−* Make all (framework-generated) HTTP errors except 404 and 405 not try other
12− handlers.
10+* Added `Delayed` and related functions (`addMethodCheck`, `addAcceptCheck`, `addBodyCheck`, `runDelayed`)
1311
14120.4.1
1513-----
servant-server/servant-server.cabal+1
@@ -95,6 +95,7 @@ test-suite spec
9595 Servant.Server.Internal.EnterSpec
9696 Servant.ServerSpec
9797 Servant.Utils.StaticFilesSpec
98+ Servant.Server.ErrorSpec
9899 build-depends:
99100 base == 4.*
100101 , aeson
servant-server/src/Servant/Server/Internal/Router.hs−1
@@ -6,7 +6,6 @@ import Data.Map (Map)
66import qualified Data.Map as M
77import Data.Text (Text)
88import Network.Wai (Request, Response, pathInfo)
9−import Servant.Server.Internal.PathInfo
109import Servant.Server.Internal.RoutingApplication
1110import Servant.Server.Internal.ServantErr
1211
servant-server/src/Servant/Server/Internal/RoutingApplication.hs+3−6
@@ -8,9 +8,7 @@
88module Servant.Server.Internal.RoutingApplication where
99
1010#if !MIN_VERSION_base(4,8,0)
11−import Control.Applicative (Applicative, (<$>))
12−import Data.Monoid (Monoid, mappend, mempty,
13− (<>))
11+import Control.Applicative ((<$>))
1412#endif
1513import Control.Monad.Trans.Except (ExceptT, runExceptT)
1614import qualified Data.ByteString as B
@@ -69,8 +67,6 @@ toApplication ra request respond = do
6967 routingRespond (FailFatal err) = respond $ responseServantErr err
7068 routingRespond (Route v) = respond v
7169
72−-- TODO: The above may not be quite right yet.
73−--
7470-- We currently mix up the order in which we perform checks
7571-- and the priority with which errors are reported.
7672--
@@ -162,7 +158,8 @@ data Delayed :: * -> * where
162158 -> (a -> b -> RouteResult c)
163159 -> Delayed c
164160
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)
166163
167164-- | Add a capture to the end of the capture block.
168165addCapture :: Delayed (a -> b)
servant-server/test/Servant/Server/ErrorSpec.hs+1−21
@@ -18,24 +18,6 @@ import Test.Hspec.Wai
1818
1919import Servant
2020
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−
3921spec :: Spec
4022spec = describe "HTTP Errors" $ do
4123 errorOrderSpec
@@ -174,9 +156,7 @@ errorRetrySpec :: Spec
174156errorRetrySpec = describe "Handler search"
175157 $ with (return $ serve errorRetryApi errorRetryServer) $ do
176158
177− let plainCT = (hContentType, "text/plain")
178− plainAccept = (hAccept, "text/plain")
179− jsonCT = (hContentType, "application/json")
159+ let jsonCT = (hContentType, "application/json")
180160 jsonAccept = (hAccept, "application/json")
181161 jsonBody = encode (1797 :: Int)
182162
servant-server/test/Servant/ServerSpec.hs+4−17
@@ -33,21 +33,6 @@ import Network.Wai (Application, Request, pathInfo,
3333import Network.Wai.Internal (Response(ResponseBuilder))
3434import Network.Wai.Test (defaultRequest, request,
3535 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
5136import Servant.API ((:<|>) (..), (:>), Capture, Delete,
5237 Get, Header (..), Headers,
5338 HttpVersion, IsSecure (..), JSON,
@@ -56,9 +41,11 @@ import Servant.API ((:<|>) (..), (:>), Capture, Delete,
5641 Raw, RemoteHost, ReqBody,
5742 addHeader)
5843import 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, (<:>))
6048import Servant.Server.Internal.RoutingApplication (toApplication, RouteResult(..))
61−>>>>>>> Rebase cleanup and test fixes.
6249import Servant.Server.Internal.Router
6350 (tweakResponse, runRouter,
6451 Router, Router'(LeafRouter))