module Network.HTTP.Semantics.Trailer where
import Network.ByteOrder
import qualified Network.HTTP.Types as H
type TrailersMaker = Maybe ByteString -> IO NextTrailersMaker
defaultTrailersMaker :: TrailersMaker
defaultTrailersMaker :: TrailersMaker
defaultTrailersMaker Maybe ByteString
Nothing = NextTrailersMaker -> IO NextTrailersMaker
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (NextTrailersMaker -> IO NextTrailersMaker)
-> NextTrailersMaker -> IO NextTrailersMaker
forall a b. (a -> b) -> a -> b
$ [Header] -> NextTrailersMaker
Trailers []
defaultTrailersMaker Maybe ByteString
_ = NextTrailersMaker -> IO NextTrailersMaker
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (NextTrailersMaker -> IO NextTrailersMaker)
-> NextTrailersMaker -> IO NextTrailersMaker
forall a b. (a -> b) -> a -> b
$ TrailersMaker -> NextTrailersMaker
NextTrailersMaker TrailersMaker
defaultTrailersMaker
data NextTrailersMaker
= NextTrailersMaker TrailersMaker
| Trailers [H.Header]
runTrailersMaker :: TrailersMaker -> Buffer -> Int -> IO NextTrailersMaker
runTrailersMaker :: TrailersMaker -> Buffer -> Int -> IO NextTrailersMaker
runTrailersMaker TrailersMaker
tlrmkr Buffer
buf Int
siz = Buffer
-> Int
-> (ByteString -> IO NextTrailersMaker)
-> IO NextTrailersMaker
forall a. Buffer -> Int -> (ByteString -> IO a) -> IO a
bufferIO Buffer
buf Int
siz ((ByteString -> IO NextTrailersMaker) -> IO NextTrailersMaker)
-> (ByteString -> IO NextTrailersMaker) -> IO NextTrailersMaker
forall a b. (a -> b) -> a -> b
$ \ByteString
bs -> TrailersMaker
tlrmkr (ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
bs)