@@ -75,10 +75,12 @@ import Servant.API
75 IsSecure (..), QueryFlag, QueryParam', QueryParams, Raw,
75 IsSecure (..), QueryFlag, QueryParam', QueryParams, Raw,
76 ReflectMethod (reflectMethod), RemoteHost, ReqBody',
76 ReflectMethod (reflectMethod), RemoteHost, ReqBody',
77 SBool (..), SBoolI (..), SourceIO, Stream, StreamBody',
77 SBool (..), SBoolI (..), SourceIO, Stream, StreamBody',
78− Summary, ToSourceIO (..), Vault, Verb, WithNamedContext)
78+ Summary, ToSourceIO (..), Vault, Verb, NoContentVerb,
79import Servant.API.ContentTypes
80import Servant.API.ContentTypes
80 (AcceptHeader (..), AllCTRender (..), AllCTUnrender (..),
81 (AcceptHeader (..), AllCTRender (..), AllCTUnrender (..),
81− AllMime, MimeRender (..), MimeUnrender (..), canHandleAcceptH)
82+ AllMime, MimeRender (..), MimeUnrender (..), canHandleAcceptH,
83+ NoContent (NoContent))
82import Servant.API.Modifiers
84import Servant.API.Modifiers
83 (FoldLenient, FoldRequired, RequestArgument,
85 (FoldLenient, FoldRequired, RequestArgument,
84 unfoldRequestArgument)
86 unfoldRequestArgument)
@@ -262,6 +264,17 @@ methodRouter splitHeaders method proxy status action = leafRouter route'
262 let bdy = if allowedMethodHead method request then "" else body
264 let bdy = if allowedMethodHead method request then "" else body
263 in Route $ responseLBS status ((hContentType, cs contentT) : headers) bdy
265 in Route $ responseLBS status ((hContentType, cs contentT) : headers) bdy
267+noContentRouter :: Method
269+ -> Delayed env (Handler b)
271+noContentRouter method status action = leafRouter route'
273+ route' env request respond =
274+ runAction (action `addMethodCheck` methodCheck method request)
275+ env request respond $ \ output ->
276+ Route $ responseLBS status [] ""
265instance {-# OVERLAPPABLE #-}
278instance {-# OVERLAPPABLE #-}
266 ( AllCTRender ctypes a, ReflectMethod method, KnownNat status
279 ( AllCTRender ctypes a, ReflectMethod method, KnownNat status
267 ) => HasServer (Verb method status ctypes a) context where
280 ) => HasServer (Verb method status ctypes a) context where
@@ -285,6 +298,15 @@ instance {-# OVERLAPPING #-}
285 where method = reflectMethod (Proxy :: Proxy method)
298 where method = reflectMethod (Proxy :: Proxy method)
286 status = toEnum . fromInteger $ natVal (Proxy :: Proxy status)
299 status = toEnum . fromInteger $ natVal (Proxy :: Proxy status)
301+instance {-# OVERLAPPABLE #-}
302+ (ReflectMethod method
303+ ) => HasServer (NoContentVerb method) context where
305+ type ServerT (NoContentVerb method) m = m NoContent
306+ hoistServerWithContext _ _ nt s = nt s
308+ route Proxy _ = noContentRouter method status204
309+ where method = reflectMethod (Proxy :: Proxy method)
289instance {-# OVERLAPPABLE #-}
311instance {-# OVERLAPPABLE #-}
290 ( MimeRender ctype chunk, ReflectMethod method, KnownNat status,
312 ( MimeRender ctype chunk, ReflectMethod method, KnownNat status,