-
- let limit = cnfMaxOutputChunkLength $ itrConfig itr
- when (limit ≤ 0)
- $ abort InternalServerError []
- (Just $ "cnfMaxOutputChunkLength must be positive: " ⊕ T.pack (show limit))
-
- discardBody ← liftIO $ atomically $
- readItr itrWillDiscardBody id itr
-
- unless (discardBody)
- $ sendChunks wholeChunk limit
-
- unless (Lazy.null wholeChunk)
- $ liftIO $ atomically $
- writeItr itrSentNoBody False itr
- where
- sendChunks ∷ Lazy.ByteString → Int → Resource ()
- sendChunks str limit
- | Lazy.null str = return ()
- | otherwise = do let (chunk, remaining) = Lazy.splitAt (fromIntegral limit) str
- itr ← getInteraction
- liftIO $ atomically
- $ putTMVar (itrBodyToSend itr) (chunkToBuilder chunk)
- sendChunks remaining limit
-
- chunkToBuilder ∷ Lazy.ByteString → Builder
- chunkToBuilder = mconcat ∘ map BB.fromByteString ∘ Lazy.toChunks
+ liftIO $ atomically
+ $ do putTMVar (itrBodyToSend itr) (BB.fromLazyByteString str)
+ unless (Lazy.null str)
+ $ writeTVar (itrSentNoBodySoFar itr) False