1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
{-# LANGUAGE DeriveDataTypeable #-}
module Network.HPACK.Types (
-- * Header
HeaderName,
HeaderValue,
Header,
HeaderList,
TokenHeader,
TokenHeaderList,
-- * Misc
Index,
HIndex (..),
-- * Encoding and decoding
CompressionAlgo (..),
EncodeStrategy (..),
defaultEncodeStrategy,
DecodeError (..),
-- * Buffer
Buffer,
BufferSize,
BufferOverrun (..),
) where
import Control.Exception as E
import Data.Typeable
import Network.ByteOrder (Buffer, BufferOverrun (..), BufferSize)
import Imports
import Network.HPACK.Token (Token)
----------------------------------------------------------------
-- | Header name.
type HeaderName = ByteString
-- | Header value.
type HeaderValue = ByteString
-- | Header.
type Header = (HeaderName, HeaderValue)
-- | Header list.
type HeaderList = [Header]
-- | TokenBased header.
type TokenHeader = (Token, HeaderValue)
-- | TokenBased header list.
type TokenHeaderList = [TokenHeader]
----------------------------------------------------------------
-- | Index for table.
type Index = Int
data HIndex = SIndex Int | DIndex Int deriving (Eq, Ord, Show)
----------------------------------------------------------------
-- | Compression algorithms for HPACK encoding.
data CompressionAlgo
= -- | No compression
Naive
| -- | Using indices in the static table only
Static
| -- | Using indices
Linear
deriving (Eq, Show)
-- | Strategy for HPACK encoding.
data EncodeStrategy = EncodeStrategy
{ compressionAlgo :: CompressionAlgo
-- ^ Which compression algorithm is used.
, useHuffman :: Bool
-- ^ Whether or not to use Huffman encoding for strings.
}
deriving (Eq, Show)
-- | Default 'EncodeStrategy'.
--
-- >>> defaultEncodeStrategy
-- EncodeStrategy {compressionAlgo = Linear, useHuffman = False}
defaultEncodeStrategy :: EncodeStrategy
defaultEncodeStrategy =
EncodeStrategy
{ compressionAlgo = Linear
, useHuffman = False
}
----------------------------------------------------------------
-- | Errors for decoder.
data DecodeError
= -- | Index is out of range
IndexOverrun Index
| -- | Eos appears in the middle of huffman string
EosInTheMiddle
| -- | Non-eos appears in the end of huffman string
IllegalEos
| -- | Eos of huffman string is more than 7 bits
TooLongEos
| -- | A peer set the dynamic table size less than 32
TooSmallTableSize
| -- | A peer tried to change the dynamic table size over the limit
TooLargeTableSize
| -- | Table size update at the non-beginning
IllegalTableSizeUpdate
| HeaderBlockTruncated
| IllegalHeaderName
| TooLargeHeader
deriving (Eq, Show, Typeable)
instance Exception DecodeError
|