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