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