module Network.HPACK.Context (
HeaderList
, Context
, newContextForEncoding
, newContextForDecoding
, changeContextForDecoding
, DecodeError(..)
, printContext
, newEntryForEncoding
, newEntryForDecoding
, getEntry
, whichTable
, lookupHeader
) where
import Control.Applicative ((<$>))
import Network.HPACK.Context.HeaderList
import Network.HPACK.Table
import Network.HPACK.Types
data Context = Context {
headerTable :: !HeaderTable
}
printContext :: Context -> IO ()
printContext (Context hdrtbl) = do
putStrLn "<<<Header table>>>"
printHeaderTable hdrtbl
putStr "\n"
newContextForEncoding :: Size -> IO Context
newContextForEncoding maxsiz = Context <$> newHeaderTableForEncoding maxsiz
newContextForDecoding :: Size -> IO Context
newContextForDecoding maxsiz = Context <$> newHeaderTableForDecoding maxsiz
changeContextForDecoding :: Context -> Size -> IO Context
changeContextForDecoding ctx@(Context hdrtbl) siz
| shouldRenew hdrtbl siz = Context <$> renewHeaderTable siz hdrtbl
| otherwise = return ctx
newEntryForEncoding :: Context -> Entry -> IO Context
newEntryForEncoding (Context hdrtbl) e = Context <$> insertEntry e hdrtbl
newEntryForDecoding :: Context -> Entry -> IO Context
newEntryForDecoding (Context hdrtbl) e = Context <$> insertEntry e hdrtbl
whichTable :: Index -> Context -> IO (WhichTable, Entry)
whichTable idx ctx = which hdrtbl idx
where
hdrtbl = headerTable ctx
lookupHeader :: Header -> Context -> HeaderCache
lookupHeader h ctx = lookupTable h (headerTable ctx)
getEntry :: Index -> Context -> IO Entry
getEntry idx ctx = snd <$> whichTable idx ctx