on master help sign in
Allow more response codes without failing
commit74b5bc400c60db477ab9bc11cf7993ed07b8cde0 authorTimo von Holtz <tvh@anchor.com.au> dateMon 9 Mar 2015, 17:04 (12 years ago) parent07d84d0
2 files changed+6−6
src/Servant/Client.hs+3−3 src/Servant/Common/Req.hs+3−3
src/Servant/Client.hs+3−3
@@ -120,7 +120,7 @@ instance HasClient Delete where
120120instance (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
121121 type Client (Get (ct ': cts) result) = BaseUrl -> EitherT ServantError IO result
122122 clientWithRoute Proxy req host =
123− performRequestCT (Proxy :: Proxy ct) H.methodGet req 200 host
123+ performRequestCT (Proxy :: Proxy ct) H.methodGet req [200] host
124124
125125-- | If you use a 'Header' in one of your endpoints in your API,
126126-- the corresponding querying function will automatically take
@@ -167,7 +167,7 @@ instance (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
167167 type Client (Post (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
168168
169169 clientWithRoute Proxy req uri =
170− performRequestCT (Proxy :: Proxy ct) H.methodPost req 201 uri
170+ performRequestCT (Proxy :: Proxy ct) H.methodPost req [200,201] uri
171171
172172-- | If you have a 'Put' endpoint in your API, the client
173173-- side querying function that is created when calling 'client'
@@ -177,7 +177,7 @@ instance (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
177177 type Client (Put (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
178178
179179 clientWithRoute Proxy req host =
180− performRequestCT (Proxy :: Proxy ct) H.methodPut req 200 host
180+ performRequestCT (Proxy :: Proxy ct) H.methodPut req [200,201] host
181181
182182-- | If you use a 'QueryParam' in one of your endpoints in your API,
183183-- the corresponding querying function will automatically take
src/Servant/Common/Req.hs+3−3
@@ -8,7 +8,7 @@ import Control.Monad
88import Control.Monad.Catch (MonadThrow)
99import Control.Monad.IO.Class
1010import Control.Monad.Trans.Either
11−import Data.ByteString.Lazy hiding (pack, filter, map, null)
11+import Data.ByteString.Lazy hiding (pack, filter, map, null, elem)
1212import Data.IORef
1313import Data.String
1414import Data.String.Conversions
@@ -162,11 +162,11 @@ performRequest reqMethod req isWantedStatus reqHost = do
162162 return (status_code, body, ct)
163163
164164performRequestCT :: MimeUnrender ct result =>
165− Proxy ct -> Method -> Req -> Int -> BaseUrl -> EitherT ServantError IO result
165+ Proxy ct -> Method -> Req -> [Int] -> BaseUrl -> EitherT ServantError IO result
166166performRequestCT ct reqMethod req wantedStatus reqHost = do
167167 let acceptCT = contentType ct
168168 (_status, respBody, respCT) <-
169− performRequest reqMethod (req { reqAccept = [acceptCT] }) (== wantedStatus) reqHost
169+ performRequest reqMethod (req { reqAccept = [acceptCT] }) (`elem` wantedStatus) reqHost
170170 unless (matches respCT (acceptCT)) $
171171 left $ UnsupportedContentType respCT respBody
172172 either