module Network.HPACK (
HPACKEncoding
, HPACKDecoding
, encodeHeader
, decodeHeader
, DynamicTable
, newDynamicTableForEncoding
, newDynamicTableForDecoding
, 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.HeaderBlock (toHeaderBlock, fromHeaderBlock, toByteStream, fromByteStream)
import Network.HPACK.Table (DynamicTable, Size, newDynamicTableForEncoding, newDynamicTableForDecoding)
import Network.HPACK.Types
type HPACKEncoding = DynamicTable -> HeaderList -> IO (DynamicTable, ByteStream)
type HPACKDecoding = DynamicTable -> ByteStream -> IO (DynamicTable, 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