module Network.HPACK (
HPACKEncoding
, HPACKDecoding
, encodeHeader
, decodeHeader
, Context
, newContextForEncoding
, newContextForDecoding
, CompressionAlgo(..)
, EncodeStrategy(..)
, defaultEncodeStrategy
, DecodeError(..)
, HeaderList
, Header
, HeaderName
, HeaderValue
, ByteStream
, Size
, Index
) where
import Control.Applicative ((<$>))
import Control.Arrow (second)
import Control.Exception (throwIO)
import Network.HPACK.Context (Context, newContextForEncoding, newContextForDecoding, HeaderList)
import Network.HPACK.HeaderBlock (toHeaderBlock, fromHeaderBlock, toByteStream, fromByteStream)
import Network.HPACK.Table (Size)
import Network.HPACK.Types
type HPACKEncoding = Context -> HeaderList -> IO (Context, ByteStream)
type HPACKDecoding = Context -> ByteStream -> IO (Context, HeaderList)
encodeHeader :: EncodeStrategy -> HPACKEncoding
encodeHeader stgy ctx hs = second toBS <$> toHeaderBlock algo ctx hs
where
algo = compressionAlgo stgy
toBS = toByteStream (useHuffman stgy)
decodeHeader :: HPACKDecoding
decodeHeader ctx bs = either throwIO (fromHeaderBlock ctx) ehb
where
ehb = fromByteStream bs