on master help sign in
Allow more response codes without failing
74b5bc4Timo von Holtz
src/Servant/Client.hs+3−3
@@ -120,7 +120,7 @@ instance HasClient Delete where
120instance (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
120instance (MimeUnrender ct result) => HasClient (Get (ct ': cts) result) where
121 type Client (Get (ct ': cts) result) = BaseUrl -> EitherT ServantError IO result
121 type Client (Get (ct ': cts) result) = BaseUrl -> EitherT ServantError IO result
122 clientWithRoute Proxy req host =
122 clientWithRoute Proxy req host =
123− performRequestCT (Proxy :: Proxy ct) H.methodGet req 200 host
123+ performRequestCT (Proxy :: Proxy ct) H.methodGet req [200] host
124
124
125-- | If you use a 'Header' in one of your endpoints in your API,
125-- | If you use a 'Header' in one of your endpoints in your API,
126-- the corresponding querying function will automatically take
126-- the corresponding querying function will automatically take
@@ -167,7 +167,7 @@ instance (MimeUnrender ct a) => HasClient (Post (ct ': cts) a) where
167 type Client (Post (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
167 type Client (Post (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
168
168
169 clientWithRoute Proxy req uri =
169 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
171
171
172-- | If you have a 'Put' endpoint in your API, the client
172-- | If you have a 'Put' endpoint in your API, the client
173-- side querying function that is created when calling 'client'
173-- side querying function that is created when calling 'client'
@@ -177,7 +177,7 @@ instance (MimeUnrender ct a) => HasClient (Put (ct ': cts) a) where
177 type Client (Put (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
177 type Client (Put (ct ': cts) a) = BaseUrl -> EitherT ServantError IO a
178
178
179 clientWithRoute Proxy req host =
179 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
181
181
182-- | If you use a 'QueryParam' in one of your endpoints in your API,
182-- | If you use a 'QueryParam' in one of your endpoints in your API,
183-- the corresponding querying function will automatically take
183-- the corresponding querying function will automatically take
src/Servant/Common/Req.hs+3−3
@@ -8,7 +8,7 @@ import Control.Monad
8import Control.Monad.Catch (MonadThrow)
8import Control.Monad.Catch (MonadThrow)
9import Control.Monad.IO.Class
9import Control.Monad.IO.Class
10import Control.Monad.Trans.Either
10import 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)
12import Data.IORef
12import Data.IORef
13import Data.String
13import Data.String
14import Data.String.Conversions
14import Data.String.Conversions
@@ -162,11 +162,11 @@ performRequest reqMethod req isWantedStatus reqHost = do
162 return (status_code, body, ct)
162 return (status_code, body, ct)
163
163
164performRequestCT :: MimeUnrender ct result =>
164performRequestCT :: 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
166performRequestCT ct reqMethod req wantedStatus reqHost = do
166performRequestCT ct reqMethod req wantedStatus reqHost = do
167 let acceptCT = contentType ct
167 let acceptCT = contentType ct
168 (_status, respBody, respCT) <-
168 (_status, respBody, respCT) <-
169− performRequest reqMethod (req { reqAccept = [acceptCT] }) (== wantedStatus) reqHost
169+ performRequest reqMethod (req { reqAccept = [acceptCT] }) (`elem` wantedStatus) reqHost
170 unless (matches respCT (acceptCT)) $
170 unless (matches respCT (acceptCT)) $
171 left $ UnsupportedContentType respCT respBody
171 left $ UnsupportedContentType respCT respBody
172 either
172 either