on master help sign in
Fix missing canonicalize changes
commitd7fcf2b19b2af04ef5104b433f87837722c826fe authorJulian K. Arni <jkarni@gmail.com> dateSun 19 Apr 2015, 18:31 (12 years ago) parenteae2f5f
3 files changed+45−44
src/Servant/Client.hs+8−7 src/Servant/Common/Req.hs+1−1 test/Servant/ClientSpec.hs+36−36
src/Servant/Client.hs+8−7
@@ -13,6 +13,7 @@
1313module Servant.Client
1414 ( client
1515 , HasClient(..)
16+ , Client
1617 , ServantError(..)
1718 , module Servant.Common.BaseUrl
1819 ) where
@@ -130,7 +131,7 @@ instance (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
130131-- | If you have a 'Get xs ()' endpoint, the client expects a 204 No Content
131132-- HTTP header.
132133instance HasClient (Get (ct ': cts) ()) where
133− type Client (Get (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
134+ type Client' (Get (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
134135 clientWithRoute Proxy req host =
135136 performRequestNoBody H.methodGet req [204] host
136137
@@ -167,7 +168,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
167168
168169 clientWithRoute Proxy req mval =
169170 clientWithRoute (Proxy :: Proxy sublayout) $
170− maybe req (\value -> addHeader hname value req) mval
171+ maybe req (\value -> Servant.Common.Req.addHeader hname value req) mval
171172
172173 where hname = symbolVal (Proxy :: Proxy sym)
173174
@@ -184,7 +185,7 @@ instance (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
184185-- | If you have a 'Post xs ()' endpoint, the client expects a 204 No Content
185186-- HTTP header.
186187instance HasClient (Post (ct ': cts) ()) where
187− type Client (Post (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
188+ type Client' (Post (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
188189 clientWithRoute Proxy req host =
189190 void $ performRequestNoBody H.methodPost req [204] host
190191
@@ -201,7 +202,7 @@ instance (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
201202-- | If you have a 'Put xs ()' endpoint, the client expects a 204 No Content
202203-- HTTP header.
203204instance HasClient (Put (ct ': cts) ()) where
204− type Client (Put (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
205+ type Client' (Put (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
205206 clientWithRoute Proxy req host =
206207 void $ performRequestNoBody H.methodPut req [204] host
207208
@@ -210,7 +211,7 @@ instance HasClient (Put (ct ': cts) ()) where
210211-- will just require an argument that specifies the scheme, host
211212-- and port to send the request to.
212213instance (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
213− type Client (Patch (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
214+ type Client' (Patch (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
214215
215216 clientWithRoute Proxy req host =
216217 performRequestCT (Proxy :: Proxy ct) H.methodPatch req [200,201] host
@@ -218,7 +219,7 @@ instance (MimeUnrender ct a) => HasClient (Patch (ct ': cts) a) where
218219-- | If you have a 'Patch xs ()' endpoint, the client expects a 204 No Content
219220-- HTTP header.
220221instance HasClient (Patch (ct ': cts) ()) where
221− type Client (Patch (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
222+ type Client' (Patch (ct ': cts) ()) = BaseUrl -> EitherT ServantError IO ()
222223 clientWithRoute Proxy req host =
223224 void $ performRequestNoBody H.methodPatch req [204] host
224225
@@ -489,7 +490,7 @@ instance (MimeRender ct a, HasClient sublayout)
489490 clientWithRoute Proxy req body =
490491 clientWithRoute (Proxy :: Proxy sublayout) $ do
491492 let ctProxy = Proxy :: Proxy ct
492− setRQBody (toByteString ctProxy body) (contentType ctProxy) req
493+ setRQBody (mimeRender ctProxy body) (contentType ctProxy) req
493494
494495-- | Make the querying function append @path@ to the request path.
495496instance (KnownSymbol path, HasClient sublayout) => HasClient (path :> sublayout) where
src/Servant/Common/Req.hs+1−1
@@ -172,7 +172,7 @@ performRequestCT ct reqMethod req wantedStatus reqHost = do
172172 either
173173 (left . (\s -> DecodeFailure s respCT respBody))
174174 return
175− (fromByteString ct respBody)
175+ (mimeUnrender ct respBody)
176176
177177performRequestNoBody :: Method -> Req -> [Int] -> BaseUrl -> EitherT ServantError IO ()
178178performRequestNoBody reqMethod req wantedStatus reqHost = do
test/Servant/ClientSpec.hs+36−36
@@ -1,42 +1,42 @@
1−{-# LANGUAGE GADTs #-}
2−{-# LANGUAGE DataKinds #-}
3−{-# LANGUAGE ViewPatterns #-}
4−{-# LANGUAGE DeriveGeneric #-}
5−{-# LANGUAGE TypeOperators #-}
6−{-# LANGUAGE RecordWildCards #-}
7−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE FlexibleContexts #-}
4+{-# LANGUAGE GADTs #-}
5+{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE RecordWildCards #-}
87{-# LANGUAGE StandaloneDeriving #-}
8+{-# LANGUAGE TypeOperators #-}
99{-# OPTIONS_GHC -fcontext-stack=25 #-}
1010{-# OPTIONS_GHC -fno-warn-orphans #-}
1111module Servant.ClientSpec where
1212
13−import Control.Applicative
14−import qualified Control.Arrow as Arrow
15−import Control.Concurrent
16−import Control.Exception
17−import Control.Monad.Trans.Either
18−import Data.Aeson
19−import Data.ByteString.Lazy (ByteString)
20−import Data.Char
21−import Data.Foldable (forM_)
22−import Data.Monoid
23−import Data.Proxy
24−import qualified Data.Text as T
25−import GHC.Generics
26−import qualified Network.HTTP.Client as C
27−import Network.HTTP.Media
28−import Network.HTTP.Types
29−import Network.Socket
30−import Network.Wai hiding (Response)
31−import Network.Wai.Handler.Warp
32−import Test.Hspec
33−import Test.Hspec.QuickCheck
34−import Test.HUnit
35−import Test.QuickCheck
36−
37−import Servant.API
38−import Servant.Client
39−import Servant.Server
13+import Control.Applicative
14+import qualified Control.Arrow as Arrow
15+import Control.Concurrent
16+import Control.Exception
17+import Control.Monad.Trans.Either
18+import Data.Aeson
19+import Data.ByteString.Lazy (ByteString)
20+import Data.Char
21+import Data.Foldable (forM_)
22+import Data.Monoid
23+import Data.Proxy
24+import qualified Data.Text as T
25+import GHC.Generics
26+import qualified Network.HTTP.Client as C
27+import Network.HTTP.Media
28+import Network.HTTP.Types
29+import Network.Socket
30+import Network.Wai hiding (Response)
31+import Network.Wai.Handler.Warp
32+import Test.Hspec
33+import Test.Hspec.QuickCheck
34+import Test.HUnit
35+import Test.QuickCheck
36+
37+import Servant.API
38+import Servant.Client
39+import Servant.Server
4040
4141-- * test data types
4242
@@ -289,8 +289,8 @@ spec = do
289289 _ -> fail $ "expected InvalidContentTypeHeader, but got " <> show res
290290
291291data WrappedApi where
292− WrappedApi :: (HasServer api, Server api ~ EitherT (Int, String) IO a,
293− HasClient api, Client api ~ (BaseUrl -> EitherT ServantError IO ())) =>
292+ WrappedApi :: (HasServer (Canonicalize api), Server api ~ EitherT (Int, String) IO a,
293+ HasClient (Canonicalize api), Client api ~ (BaseUrl -> EitherT ServantError IO ())) =>
294294 Proxy api -> WrappedApi
295295
296296