@@ -65,7 +65,7 @@ import Data.Text
65import Data.Proxy
65import Data.Proxy
66 (Proxy (Proxy))
66 (Proxy (Proxy))
67import GHC.TypeLits
67import GHC.TypeLits
68− (KnownSymbol, symbolVal)
68+ (KnownNat, KnownSymbol, symbolVal)
69import Network.HTTP.Types
69import Network.HTTP.Types
71import qualified Network.HTTP.Types as H
71import qualified Network.HTTP.Types as H
@@ -86,6 +86,8 @@ import Servant.API.Generic
86 , GenericServant, toServant, fromServant)
86 , GenericServant, toServant, fromServant)
87import Servant.API.ContentTypes
87import Servant.API.ContentTypes
88 (contentTypes, AllMime (allMime), AllMimeUnrender (allMimeUnrender))
88 (contentTypes, AllMime (allMime), AllMimeUnrender (allMimeUnrender))
89+import Servant.API.Status
89import Servant.API.TypeLevel (FragmentUnique, AtLeastOneFragment)
91import Servant.API.TypeLevel (FragmentUnique, AtLeastOneFragment)
90import Servant.API.Modifiers
92import Servant.API.Modifiers
91 (FoldRequired, RequiredArgument, foldRequiredArgument)
93 (FoldRequired, RequiredArgument, foldRequiredArgument)
@@ -250,10 +252,11 @@ instance (KnownSymbol capture, ToHttpApiData a, HasClient m sublayout)
250instance {-# OVERLAPPABLE #-}
252instance {-# OVERLAPPABLE #-}
251 -- Note [Non-Empty Content Types]
253 -- Note [Non-Empty Content Types]
252 ( RunClient m, MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts)
254 ( RunClient m, MimeUnrender ct a, ReflectMethod method, cts' ~ (ct ': cts)
253 ) => HasClient m (Verb method status cts' a) where
256 ) => HasClient m (Verb method status cts' a) where
254 type Client m (Verb method status cts' a) = m a
257 type Client m (Verb method status cts' a) = m a
255 clientWithRoute _pm Proxy req = do
258 clientWithRoute _pm Proxy req = do
256− response <- runRequest req
259+ response <- runRequestAcceptStatus (Just [status]) req
257 { requestAccept = fromList $ toList accept
260 { requestAccept = fromList $ toList accept
258 , requestMethod = method
261 , requestMethod = method
@@ -261,18 +264,20 @@ instance {-# OVERLAPPABLE #-}
262 accept = contentTypes (Proxy :: Proxy ct)
265 accept = contentTypes (Proxy :: Proxy ct)
263 method = reflectMethod (Proxy :: Proxy method)
266 method = reflectMethod (Proxy :: Proxy method)
267+ status = statusFromNat (Proxy :: Proxy status)
265 hoistClientMonad _ _ f ma = f ma
269 hoistClientMonad _ _ f ma = f ma
267instance {-# OVERLAPPING #-}
271instance {-# OVERLAPPING #-}
268− ( RunClient m, ReflectMethod method
272+ ( RunClient m, ReflectMethod method, KnownNat status
269 ) => HasClient m (Verb method status cts NoContent) where
273 ) => HasClient m (Verb method status cts NoContent) where
270 type Client m (Verb method status cts NoContent)
274 type Client m (Verb method status cts NoContent)
271 = m NoContent
275 = m NoContent
272 clientWithRoute _pm Proxy req = do
276 clientWithRoute _pm Proxy req = do
273− _response <- runRequest req { requestMethod = method }
277+ _response <- runRequestAcceptStatus (Just [status]) req { requestMethod = method }
274 return NoContent
278 return NoContent
275 where method = reflectMethod (Proxy :: Proxy method)
279 where method = reflectMethod (Proxy :: Proxy method)
280+ status = statusFromNat (Proxy :: Proxy status)
277 hoistClientMonad _ _ f ma = f ma
282 hoistClientMonad _ _ f ma = f ma
@@ -289,13 +294,13 @@ instance (RunClient m, ReflectMethod method) =>
290instance {-# OVERLAPPING #-}
295instance {-# OVERLAPPING #-}
291 -- Note [Non-Empty Content Types]
296 -- Note [Non-Empty Content Types]
292− ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls
297+ ( RunClient m, MimeUnrender ct a, BuildHeadersTo ls, KnownNat status
293 , ReflectMethod method, cts' ~ (ct ': cts)
298 , ReflectMethod method, cts' ~ (ct ': cts)
294 ) => HasClient m (Verb method status cts' (Headers ls a)) where
299 ) => HasClient m (Verb method status cts' (Headers ls a)) where
295 type Client m (Verb method status cts' (Headers ls a))
300 type Client m (Verb method status cts' (Headers ls a))
296 = m (Headers ls a)
301 = m (Headers ls a)
297 clientWithRoute _pm Proxy req = do
302 clientWithRoute _pm Proxy req = do
298− response <- runRequest req
303+ response <- runRequestAcceptStatus (Just [status]) req
299 { requestMethod = method
304 { requestMethod = method
300 , requestAccept = fromList $ toList accept
305 , requestAccept = fromList $ toList accept
@@ -303,22 +308,26 @@ instance {-# OVERLAPPING #-}
303 return $ Headers { getResponse = val
308 return $ Headers { getResponse = val
304 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
309 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
306− where method = reflectMethod (Proxy :: Proxy method)
312+ method = reflectMethod (Proxy :: Proxy method)
307− accept = contentTypes (Proxy :: Proxy ct)
313+ accept = contentTypes (Proxy :: Proxy ct)
314+ status = statusFromNat (Proxy :: Proxy status)
309 hoistClientMonad _ _ f ma = f ma
316 hoistClientMonad _ _ f ma = f ma
311instance {-# OVERLAPPING #-}
318instance {-# OVERLAPPING #-}
312− ( RunClient m, BuildHeadersTo ls, ReflectMethod method
319+ ( RunClient m, BuildHeadersTo ls, ReflectMethod method, KnownNat status
313 ) => HasClient m (Verb method status cts (Headers ls NoContent)) where
320 ) => HasClient m (Verb method status cts (Headers ls NoContent)) where
314 type Client m (Verb method status cts (Headers ls NoContent))
321 type Client m (Verb method status cts (Headers ls NoContent))
315 = m (Headers ls NoContent)
322 = m (Headers ls NoContent)
316 clientWithRoute _pm Proxy req = do
323 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 }
319 return $ Headers { getResponse = NoContent
325 return $ Headers { getResponse = NoContent
320 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
326 , getHeadersHList = buildHeadersTo . toList $ responseHeaders response
329+ method = reflectMethod (Proxy :: Proxy method)
330+ status = statusFromNat (Proxy :: Proxy status)
323 hoistClientMonad _ _ f ma = f ma
332 hoistClientMonad _ _ f ma = f ma
@@ -784,7 +793,7 @@ instance ( HasClient m api
785-- | Ignore @'Fragment'@ in client functions.
794-- | Ignore @'Fragment'@ in client functions.
786-- See <https://ietf.org/rfc/rfc2616.html#section-15.1.3> for more details.
795-- See <https://ietf.org/rfc/rfc2616.html#section-15.1.3> for more details.
788-- Example:
797-- Example:
790-- > type MyApi = "books" :> Fragment Text :> Get '[JSON] [Book]
799-- > type MyApi = "books" :> Fragment Text :> Get '[JSON] [Book]
@@ -801,7 +810,7 @@ instance (AtLeastOneFragment api, FragmentUnique (Fragment a :> api), HasClient
802 type Client m (Fragment a :> api) = Client m api
811 type Client m (Fragment a :> api) = Client m api
804− clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
813+ clientWithRoute pm _ = clientWithRoute pm (Proxy :: Proxy api)
806 hoistClientMonad pm _ = hoistClientMonad pm (Proxy :: Proxy api)
815 hoistClientMonad pm _ = hoistClientMonad pm (Proxy :: Proxy api)