我正在使用管道和 WAI 来传输音频。问题是我需要先查看安全管道中的一些数据,然后根据提取的信息选择响应标头,然后继续将该管道作为响应主体进行流式传输。这是我现在所拥有的,并且工作正常:
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
是标准Application的函数参数,Mpeg.headerFromPipe
是我的前瞻性计算:
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 ()
所以问题是:有什么方法可以在和用于选择标题respond
之间移动。我无法拆分并分成两个不同的 SafeT计算线程,因为首先将完成管道和管道(这是执行几次、检查数据、返回内容并与其余部分链接的结果)将失败。headerFromPipe
for
mph
responseStream
headerFromPipe
for
runSafeT
chunks
next