git.iko.soy/typeable/servant
on master help sign in
Routing strips path snippets (and Raw receives modified Requests)
commitc98c7db0dfc7c53ac22f4d6dba55be93f224ace8 authorSönke Hahn <soenke.hahn@zalora.com> dateTue 28 Oct 2014, 17:42 (12 years ago) parenta7c1ec1
12 files changed+25−26
src/Servant/API/Capture.hs+2−2 src/Servant/API/Delete.hs+1−1 src/Servant/API/Get.hs+1−1 src/Servant/API/GetParam.hs+2−2 src/Servant/API/Post.hs+1−1 src/Servant/API/Put.hs+1−1 src/Servant/API/RQBody.hs+2−2 src/Servant/API/Raw.hs+5−4 src/Servant/API/Sub.hs+2−2 src/Servant/API/Union.hs+3−3 src/Servant/Server.hs+2−4 test/Servant/ServerSpec.hs+3−3
src/Servant/API/Capture.hs+2−2
@@ -28,11 +28,11 @@ instance (KnownSymbol capture, FromText a, HasServer sublayout)
2828 type Server (Capture capture a :> sublayout) =
2929 a -> Server sublayout
3030
31− route Proxy subserver globalPathInfo request respond = case pathInfo request of
31+ route Proxy subserver request respond = case pathInfo request of
3232 (first : rest)
3333 -> case captured captureProxy first of
3434 Nothing -> respond Nothing
35− Just v -> route (Proxy :: Proxy sublayout) (subserver v) globalPathInfo request{
35+ Just v -> route (Proxy :: Proxy sublayout) (subserver v) request{
3636 pathInfo = rest
3737 } respond
3838 _ -> respond Nothing
src/Servant/API/Delete.hs+1−1
@@ -23,7 +23,7 @@ data Delete
2323instance HasServer Delete where
2424 type Server Delete = EitherT (Int, String) IO ()
2525
26− route Proxy action _globalPathInfo request respond
26+ route Proxy action request respond
2727 | null (pathInfo request) && requestMethod request == methodDelete = do
2828 e <- runEitherT action
2929 respond $ Just $ case e of
src/Servant/API/Get.hs+1−1
@@ -24,7 +24,7 @@ data Get a
2424
2525instance ToJSON result => HasServer (Get result) where
2626 type Server (Get result) = EitherT (Int, String) IO result
27− route Proxy action _globalPathInfo request respond
27+ route Proxy action request respond
2828 | null (pathInfo request) && requestMethod request == methodGet = do
2929 e <- runEitherT action
3030 respond $ Just $ case e of
src/Servant/API/GetParam.hs+2−2
@@ -27,7 +27,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
2727 type Server (GetParam sym a :> sublayout) =
2828 Maybe a -> Server sublayout
2929
30− route Proxy subserver globalPathInfo request respond = do
30+ route Proxy subserver request respond = do
3131 let querytext = parseQueryText $ rawQueryString request
3232 param =
3333 case lookup paramname querytext of
@@ -36,7 +36,7 @@ instance (KnownSymbol sym, FromText a, HasServer sublayout)
3636 Just (Just v) -> fromText v -- if present, we try to convert to
3737 -- the right type
3838
39− route (Proxy :: Proxy sublayout) (subserver param) globalPathInfo request respond
39+ route (Proxy :: Proxy sublayout) (subserver param) request respond
4040
4141 where paramname = cs $ symbolVal (Proxy :: Proxy sym)
4242
src/Servant/API/Post.hs+1−1
@@ -26,7 +26,7 @@ data Post a
2626instance ToJSON a => HasServer (Post a) where
2727 type Server (Post a) = EitherT (Int, String) IO a
2828
29− route Proxy action _globalPathInfo request respond
29+ route Proxy action request respond
3030 | null (pathInfo request) && requestMethod request == methodPost = do
3131 e <- runEitherT action
3232 respond $ Just $ case e of
src/Servant/API/Put.hs+1−1
@@ -24,7 +24,7 @@ data Put a
2424instance ToJSON a => HasServer (Put a) where
2525 type Server (Put a) = EitherT (Int, String) IO a
2626
27− route Proxy action _globalPathInfo request respond
27+ route Proxy action request respond
2828 | null (pathInfo request) && requestMethod request == methodPut = do
2929 e <- runEitherT action
3030 respond $ Just $ case e of
src/Servant/API/RQBody.hs+2−2
@@ -23,11 +23,11 @@ instance (FromJSON a, HasServer sublayout)
2323 type Server (RQBody a :> sublayout) =
2424 a -> Server sublayout
2525
26− route Proxy subserver globalPathInfo request respond = do
26+ route Proxy subserver request respond = do
2727 mrqbody <- decode' <$> lazyRequestBody request
2828 case mrqbody of
2929 Nothing -> respond Nothing
30− Just v -> route (Proxy :: Proxy sublayout) (subserver v) globalPathInfo request respond
30+ Just v -> route (Proxy :: Proxy sublayout) (subserver v) request respond
3131
3232instance (ToJSON a, HasClient sublayout)
3333 => HasClient (RQBody a :> sublayout) where
src/Servant/API/Raw.hs+5−4
@@ -7,11 +7,12 @@ import Network.Wai
77import Servant.Server
88
99-- | Endpoint for plugging in your own Wai 'Application's.
10−-- The given Application will get the original request received by the server
11−-- (i.e. with unmodified 'pathInfo', etc.)
10+--
11+-- The given 'Application' will get the request as received by the server, potentially with
12+-- a modified (stripped) 'pathInfo' if the 'Application' is being routed with 'Servant.API.Sub.:>'.
1213data Raw
1314
1415instance HasServer Raw where
1516 type Server Raw = Application
16− route Proxy rawApplication globalPathInfo request respond =
17− rawApplication request{pathInfo = globalPathInfo} (respond . Just)
17+ route Proxy rawApplication request respond =
18+ rawApplication request (respond . Just)
src/Servant/API/Sub.hs+2−2
@@ -19,10 +19,10 @@ infixr 9 :>
1919
2020instance (KnownSymbol path, HasServer sublayout) => HasServer (path :> sublayout) where
2121 type Server (path :> sublayout) = Server sublayout
22− route Proxy subserver globalPathInfo request respond = case pathInfo request of
22+ route Proxy subserver request respond = case pathInfo request of
2323 (first : rest)
2424 | first == cs (symbolVal proxyPath)
25− -> route (Proxy :: Proxy sublayout) subserver globalPathInfo request{
25+ -> route (Proxy :: Proxy sublayout) subserver request{
2626 pathInfo = rest
2727 } respond
2828 _ -> respond Nothing
src/Servant/API/Union.hs+3−3
@@ -14,10 +14,10 @@ infixr 8 :<|>
1414
1515instance (HasServer a, HasServer b) => HasServer (a :<|> b) where
1616 type Server (a :<|> b) = Server a :<|> Server b
17− route Proxy (a :<|> b) globalPathInfo request respond = do
18− route (Proxy :: Proxy a) a globalPathInfo request $ \ mResponse ->
17+ route Proxy (a :<|> b) request respond = do
18+ route (Proxy :: Proxy a) a request $ \ mResponse ->
1919 case mResponse of
20− Nothing -> route (Proxy :: Proxy b) b globalPathInfo request respond
20+ Nothing -> route (Proxy :: Proxy b) b request respond
2121 Just resp -> respond $ Just resp
2222
2323instance (HasClient a, HasClient b) => HasClient (a :<|> b) where
src/Servant/Server.hs+2−4
@@ -8,7 +8,6 @@
88module Servant.Server where
99
1010import Data.Proxy
11−import Data.Text
1211import Network.HTTP.Types
1312import Network.Wai
1413
@@ -20,7 +19,7 @@ serve p server = toApplication (route p server)
2019
2120toApplication :: RoutingApplication -> Application
2221toApplication ra request respond = do
23− ra (pathInfo request) request routingRespond
22+ ra request routingRespond
2423 where
2524 routingRespond :: Maybe Response -> IO ResponseReceived
2625 routingRespond Nothing =
@@ -29,8 +28,7 @@ toApplication ra request respond = do
2928 respond response
3029
3130type RoutingApplication =
32− [Text] -- ^ the unmodified 'pathInfo'
33− -> Request -- ^ the request, the field 'pathInfo' may be modified by url routing
31+ Request -- ^ the request, the field 'pathInfo' may be modified by url routing
3432 -> (Maybe Response -> IO ResponseReceived) -> IO ResponseReceived
3533
3634class HasServer layout where
test/Servant/ServerSpec.hs+3−3
@@ -164,13 +164,13 @@ rawSpec = do
164164 liftIO $ do
165165 simpleBody response `shouldBe` "42"
166166
167− it "gets the pathInfo unmodified" $ do
167+ it "gets the pathInfo modified" $ do
168168 (flip runSession) (serve rawApi (rawApplication pathInfo)) $ do
169169 response <- Network.Wai.Test.request defaultRequest{
170− pathInfo = ["foo"]
170+ pathInfo = ["foo", "bar"]
171171 }
172172 liftIO $ do
173− simpleBody response `shouldBe` cs (show ["foo" :: String])
173+ simpleBody response `shouldBe` cs (show ["bar" :: String])
174174
175175
176176type UnionApi =