Skip to content

Commit 4edd164

Browse files
authored
Merge pull request #1197 from sopvop/headers-stream
HasClient instance for Stream with Headers
2 parents d428993 + dbd92a4 commit 4edd164

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

servant-client-core/src/Servant/Client/Core/HasClient.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,31 @@ instance {-# OVERLAPPABLE #-}
297297
, requestMethod = reflectMethod (Proxy :: Proxy method)
298298
}
299299

300+
instance {-# OVERLAPPING #-}
301+
( RunStreamingClient m, MimeUnrender ct chunk, ReflectMethod method,
302+
FramingUnrender framing, FromSourceIO chunk a,
303+
BuildHeadersTo hs
304+
) => HasClient m (Stream method status framing ct (Headers hs a)) where
305+
306+
type Client m (Stream method status framing ct (Headers hs a)) = m (Headers hs a)
307+
308+
hoistClientMonad _ _ f ma = f ma
309+
310+
clientWithRoute _pm Proxy req = withStreamingRequest req' $ \gres -> do
311+
let mimeUnrender' = mimeUnrender (Proxy :: Proxy ct) :: BL.ByteString -> Either String chunk
312+
framingUnrender' = framingUnrender (Proxy :: Proxy framing) mimeUnrender'
313+
val = fromSourceIO $ framingUnrender' $ responseBody gres
314+
return $ Headers
315+
{ getResponse = val
316+
, getHeadersHList = buildHeadersTo . toList $ responseHeaders gres
317+
}
318+
319+
where
320+
req' = req
321+
{ requestAccept = fromList [contentType (Proxy :: Proxy ct)]
322+
, requestMethod = reflectMethod (Proxy :: Proxy method)
323+
}
324+
300325
-- | If you use a 'Header' in one of your endpoints in your API,
301326
-- the corresponding querying function will automatically take
302327
-- an additional argument of the type specified by your 'Header',

0 commit comments

Comments
 (0)