@@ -292,26 +292,42 @@ noContentRouter method status action = leafRouter route'
292292 env request respond $ \ _output ->
293293 Route $ responseLBS status [] " "
294294
295- instance {-# OVERLAPPABLE #-}
296- ( AllCTRender ctypes a , ReflectMethod method , KnownNat status
297- ) => HasServer (Verb method status ctypes a ) context where
295+ newtype Naked a = Naked a
298296
299- type ServerT (Verb method status ctypes a ) m = m a
300- hoistServerWithContext _ _ nt s = nt s
297+ type family Wrap a where
298+ Wrap (Headers x a ) = Headers x a
299+ Wrap a = Naked a
301300
302- route Proxy _ = methodRouter ( [] ,) method ( Proxy :: Proxy ctypes ) status
303- where method = reflectMethod ( Proxy :: Proxy method )
304- status = statusFromNat ( Proxy :: Proxy status )
301+ class ExtractHeadersResponse orig wrapped where
302+ type HandlerResponse orig wrapped :: *
303+ type ExtractedValue orig wrapped :: *
305304
306- instance {-# OVERLAPPING #-}
307- ( AllCTRender ctypes a , ReflectMethod method , KnownNat status
308- , GetHeaders (Headers h a )
309- ) => HasServer (Verb method status ctypes (Headers h a )) context where
305+ extractHeadersResponse :: HandlerResponse orig wrapped -> (([(HeaderName , B. ByteString )]), ExtractedValue orig wrapped )
310306
311- type ServerT (Verb method status ctypes (Headers h a )) m = m (Headers h a )
307+ instance ExtractHeadersResponse a (Naked a ) where
308+ type HandlerResponse a (Naked a ) = a
309+ type ExtractedValue a (Naked a ) = a
310+
311+ extractHeadersResponse :: a -> (([(HeaderName , B. ByteString )]), a )
312+ extractHeadersResponse x = ([] , x)
313+
314+ instance GetHeaders (Headers x a ) => ExtractHeadersResponse (Headers x a ) (Headers x a ) where
315+ type HandlerResponse (Headers x a ) (Headers x a ) = Headers x a
316+ type ExtractedValue (Headers x a ) (Headers x a ) = a
317+
318+ extractHeadersResponse :: Headers x a -> ([(HeaderName , B. ByteString )], a )
319+ extractHeadersResponse x = (getHeaders x, getResponse x)
320+
321+ instance ( AllCTRender ctypes (ExtractedValue a (Wrap a ))
322+ , ReflectMethod method , KnownNat status
323+ , ExtractHeadersResponse a (Wrap a )
324+ , a ~ HandlerResponse a (Wrap a )
325+ ) => HasServer (Verb method status ctypes a ) context where
326+
327+ type ServerT (Verb method status ctypes a ) m = m a
312328 hoistServerWithContext _ _ nt s = nt s
313329
314- route Proxy _ = methodRouter (\ x -> (getHeaders x, getResponse x )) method (Proxy :: Proxy ctypes ) status
330+ route Proxy _ = methodRouter (extractHeadersResponse @ a @ ( Wrap a )) method (Proxy :: Proxy ctypes ) status
315331 where method = reflectMethod (Proxy :: Proxy method )
316332 status = statusFromNat (Proxy :: Proxy status )
317333
0 commit comments