{-# LANGUAGE Safe #-}

module Network.HTTP.Pony.ServeSafe where

import Data.ByteString (ByteString)
import Pipes (Effect, Producer, Consumer, runEffect, (>->))

serveWithPipe :: (Monad m)  => Producer ByteString m a
                            -> Consumer ByteString m b
                            -> (Producer ByteString m a -> m (Producer ByteString m b))
                            -> m ()
serveWithPipe pull push pipe = do
  r <- pipe pull
  runEffect (r >-> push)

  pure ()