@@ -65,7 +65,7 @@ import Data.Text
6565import Data.Proxy
6666 (Proxy (Proxy))
6767import GHC.TypeLits
68− (KnownSymbol, symbolVal)
68+ (KnownNat, KnownSymbol, symbolVal)
6969import Network.HTTP.Types
7070 (Status)
7171import qualified Network.HTTP.Types as H
@@ -86,6 +86,8 @@ import Servant.API.Generic
8686 , GenericServant, toServant, fromServant)
8787import Servant.API.ContentTypes
8888 (contentTypes, AllMime (allMime), AllMimeUnrender (allMimeUnrender))
89+import Servant.API.Status
90+ (statusFromNat)
8991import Servant.API.TypeLevel (FragmentUnique, AtLeastOneFragment)
9092import Servant.API.Modifiers
9193 (FoldRequired, RequiredArgument, foldRequiredArgument)
@@ -250,10 +252,11 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m sublayout)
250252instance {-# OVERLAPPABLE #-}
251253 -- Note [Non-Empty Content Types]
252254 ( RunClient m, MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts)
255+ , KnownNat status
253256 ) => HasClient m (Verb method status cts' a) where
254257 type Client m (Verb method status cts' a) = m a
255258 clientWithRoute _pm Proxy req = do
256− response <- runRequest req
259+ response <- runRequestAcceptStatus (Just [status]) req
257260 { requestAccept = fromList $ toList accept
258261 , requestMethod = method
259262 }
@@ -261,18 +264,20 @@ instance {-# OVERLAPPABLE #-}
261264 where
262265 accept = contentTypes (Proxy :: Proxy ct)
263266 method = reflectMethod (Proxy :: Proxy method)
267+ status = statusFromNat (Proxy :: Proxy status)
264268
265269 hoistClientMonad _ _ f ma = f ma
266270
267271instance {-# OVERLAPPING #-}
268− ( RunClient m, ReflectMethod method
272+ ( RunClient m, ReflectMethod method, KnownNat status
269273 ) => HasClient m (Verb method status cts NoContent) where
270274 type Client m (Verb method status cts NoContent)
271275 = m NoContent
272276 clientWithRoute _pm Proxy req = do
273− _response <- runRequest req { requestMethod = method }
277+ _response <- runRequestAcceptStatus (Just [status]) req { requestMethod = method }
274278 return NoContent
275279 where method = reflectMethod (Proxy :: Proxy method)
280+ status = statusFromNat (Proxy :: Proxy status)
276281
277282 hoistClientMonad _ _ f ma = f ma
278283
@@ -289,13 +294,13 @@ instance (RunClient m, ReflectMethod method) =>
289294
290295instance {-# OVERLAPPING #-}
291296 -- Note [Non-Empty Content Types]
292− ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls
297+ ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls, KnownNat status
293298 , ReflectMethod method, cts' ~ (ct ': cts)
294299 ) => HasClient m (Verb method status cts' (Headers ls a)) where
295300 type Client m (Verb method status cts' (Headers ls a))
296301 = m (Headers ls a)
297302 clientWithRoute _pm Proxy req = do
298− response <- runRequest req
303+ response <- runRequestAcceptStatus (Just [status]) req
299304 { requestMethod = method
300305 , requestAccept = fromList $ toList accept
301306 }
@@ -303,22 +308,26 @@ instance {-# OVERLAPPING #-}
303308 return $ Headers { getResponse = val
304309 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
305310 }
306− where method = reflectMethod (Proxy :: Proxy method)
307− accept = contentTypes (Proxy :: Proxy ct)
311+ where
312+ method = reflectMethod (Proxy :: Proxy method)
313+ accept = contentTypes (Proxy :: Proxy ct)
314+ status = statusFromNat (Proxy :: Proxy status)
308315
309316 hoistClientMonad _ _ f ma = f ma
310317
311318instance {-# OVERLAPPING #-}
312− ( RunClient m, BuildHeadersTo ls, ReflectMethod method
319+ ( RunClient m, BuildHeadersTo ls, ReflectMethod method, KnownNat status
313320 ) => HasClient m (Verb method status cts (Headers ls NoContent)) where
314321 type Client m (Verb method status cts (Headers ls NoContent))
315322 = m (Headers ls NoContent)
316323 clientWithRoute _pm Proxy req = do
317− let method = reflectMethod (Proxy :: Proxy method)
318− response <- runRequest req { requestMethod = method }
324+ response <- runRequestAcceptStatus (Just [status]) req { requestMethod = method }
319325 return $ Headers { getResponse = NoContent
320326 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
321327 }
328+ where
329+ method = reflectMethod (Proxy :: Proxy method)
330+ status = statusFromNat (Proxy :: Proxy status)
322331
323332 hoistClientMonad _ _ f ma = f ma
324333
@@ -784,7 +793,7 @@ instance ( HasClient m api
784793
785794-- | Ignore @'Fragment'@ in client functions.
786795-- See <https://ietf.org/rfc/rfc2616.html#section-15.1.3> for more details.
787−--
796+--
788797-- Example:
789798--
790799-- > type MyApi = "books" :> Fragment Text :> Get '[JSON] [Book]
@@ -801,7 +810,7 @@ instance (AtLeastOneFragment api, FragmentUnique (Fragment a :> api), HasClient
801810
802811 type Client m (Fragment a :> api) = Client m api
803812
804− clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
813+ clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
805814
806815 hoistClientMonad pm _ = hoistClientMonad pm (Proxy :: Proxy api)
807816