module Network.HPACK (
HPACKEncoding
, HPACKDecoding
, encodeRequestHeader
, decodeRequestHeader
, encodeResponseHeader
, decodeResponseHeader
, Context
, newContextForEncoding
, newContextForDecoding
, CompressionAlgo(..)
, EncodeStrategy(..)
, defaultEncodeStrategy
, DecodeError(..)
, HeaderSet
, 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, HeaderSet)
import Network.HPACK.HeaderBlock (toHeaderBlock, fromHeaderBlock, toByteStream, fromByteStream)
import Network.HPACK.Huffman (huffmanEncodeInRequest, huffmanDecodeInRequest, huffmanEncodeInResponse, huffmanDecodeInResponse)
import Network.HPACK.Table (Size)
import Network.HPACK.Types
type HPACKEncoding = Context -> HeaderSet -> IO (Context, ByteStream)
type HPACKDecoding = Context -> ByteStream -> IO (Context, HeaderSet)
encodeRequestHeader :: EncodeStrategy -> HPACKEncoding
encodeRequestHeader stgy ctx hs = second toBS <$> toHeaderBlock algo ctx hs
where
algo = compressionAlgo stgy
toBS
| useHuffman stgy = toByteStream huffmanEncodeInRequest True
| otherwise = toByteStream id False
decodeRequestHeader :: HPACKDecoding
decodeRequestHeader ctx bs = either throwIO (fromHeaderBlock ctx) ehb
where
ehb = fromByteStream huffmanDecodeInRequest bs
encodeResponseHeader :: EncodeStrategy -> HPACKEncoding
encodeResponseHeader stgy ctx hs = second toBS <$> toHeaderBlock algo ctx hs
where
algo = compressionAlgo stgy
toBS
| useHuffman stgy = toByteStream huffmanEncodeInResponse True
| otherwise = toByteStream id False
decodeResponseHeader :: HPACKDecoding
decodeResponseHeader ctx bs = either throwIO (fromHeaderBlock ctx) ehb
where
ehb = fromByteStream huffmanDecodeInResponse bs