Intermediate flow WAI with safety pipes
I am using channels and WAI for audio streaming. The problem is that I need to look at some data in a safe-pipe and then select the response headers based on the information fetched and then continue to stream that pipe as the response body. Here's what I have now and what works well:
respond $ Wai.responseStream status200 headers $ \write flush -> do
runSafeT $ runEffect $ do
(mph, chunks) <- lift $ Mpeg.headerFromPipe pipe
for chunks $ \chunk -> liftIO $ do
write $ BB.byteString chunk
flush
respond
is the standard Application funarg, and Mpeg.headerFromPipe
this is my perspective computation:
respond :: Response -> IO ResponseReceived
Mpeg.headerFromPipe :: Monad m
=> Producer ByteString m r
-> m (Mpeg.Header, Producer ByteString m r)
pipe :: Producer ByteString (SafeT IO) ()
Wai.responseStream :: Status -> ResponseHeaders -> StreamingBody -> Response
type StreamingBody = (Builder -> IO ()) -> IO () -> IO ()
So the question is: is there a way to move respond
between headerFromPipe
and for
to use mph
to select the headings to give responseStream
. I cannot split headerFromPipe
and for
into two different SafeT -goods, because then the first one runSafeT
will complete the pipe and the pipe chunks
(which is the result several times next
, checking the data, putting the stuff back and chains with the remainder) will fail.
source to share
No one has answered this question yet
Check out similar questions: