{-# LANGUAGE OverloadedStrings #-}

module Network.HPACK.Table.Static (
    toStaticEntry
  , staticTableSize
  , staticTableList
  ) where

import Data.Array (Array, listArray)
import Data.Array.Base (unsafeAt)
import Network.HPACK.Table.Entry

----------------------------------------------------------------

-- | The size of static table.
staticTableSize :: Size
staticTableSize :: Size
staticTableSize = [Header] -> Size
forall (t :: * -> *) a. Foldable t => t a -> Size
length [Header]
staticTableList

{-# INLINE toStaticEntry #-}
-- | Get 'Entry' from the static table.
--
-- >>> toStaticEntry 1
-- Entry 42 (Token {ix = 0, shouldBeIndexed = True, isPseudo = True, tokenKey = ":authority"}) ""
-- >>> toStaticEntry 8
-- Entry 42 (Token {ix = 4, shouldBeIndexed = True, isPseudo = True, tokenKey = ":status"}) "200"
-- >>> toStaticEntry 50
-- Entry 37 (Token {ix = 40, shouldBeIndexed = True, isPseudo = False, tokenKey = "Range"}) ""
toStaticEntry :: Index -> Entry
toStaticEntry :: Size -> Entry
toStaticEntry sidx :: Size
sidx = Array Size Entry
staticTable Array Size Entry -> Size -> Entry
forall (a :: * -> * -> *) e i.
(IArray a e, Ix i) =>
a i e -> Size -> e
`unsafeAt` (Size
sidx Size -> Size -> Size
forall a. Num a => a -> a -> a
- 1)

-- | Pre-defined static table.
staticTable :: Array Index Entry
staticTable :: Array Size Entry
staticTable = (Size, Size) -> [Entry] -> Array Size Entry
forall i e. Ix i => (i, i) -> [e] -> Array i e
listArray (1,Size
staticTableSize) ([Entry] -> Array Size Entry) -> [Entry] -> Array Size Entry
forall a b. (a -> b) -> a -> b
$ (Header -> Entry) -> [Header] -> [Entry]
forall a b. (a -> b) -> [a] -> [b]
map Header -> Entry
toEntry [Header]
staticTableList

----------------------------------------------------------------

staticTableList :: [Header]
staticTableList :: [Header]
staticTableList = [
    (":authority", "")
  , (":method", "GET")
  , (":method", "POST")
  , (":path", "/")
  , (":path", "/index.html")
  , (":scheme", "http")
  , (":scheme", "https")
  , (":status", "200")
  , (":status", "204")
  , (":status", "206")
  , (":status", "304")
  , (":status", "400")
  , (":status", "404")
  , (":status", "500")
  , ("accept-charset", "")
  , ("accept-encoding", "gzip, deflate")
  , ("accept-language", "")
  , ("accept-ranges", "")
  , ("accept", "")
  , ("access-control-allow-origin", "")
  , ("age", "")
  , ("allow", "")
  , ("authorization", "")
  , ("cache-control", "")
  , ("content-disposition", "")
  , ("content-encoding", "")
  , ("content-language", "")
  , ("content-length", "")
  , ("content-location", "")
  , ("content-range", "")
  , ("content-type", "")
  , ("cookie", "")
  , ("date", "")
  , ("etag", "")
  , ("expect", "")
  , ("expires", "")
  , ("from", "")
  , ("host", "")
  , ("if-match", "")
  , ("if-modified-since", "")
  , ("if-none-match", "")
  , ("if-range", "")
  , ("if-unmodified-since", "")
  , ("last-modified", "")
  , ("link", "")
  , ("location", "")
  , ("max-forwards", "")
  , ("proxy-authenticate", "")
  , ("proxy-authorization", "")
  , ("range", "")
  , ("referer", "")
  , ("refresh", "")
  , ("retry-after", "")
  , ("server", "")
  , ("set-cookie", "")
  , ("strict-transport-security", "")
  , ("transfer-encoding", "")
  , ("user-agent", "")
  , ("vary", "")
  , ("via", "")
  , ("www-authenticate", "")
  ]