{-# 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 {tokenIx = 0, shouldBeIndexed = True, isPseudo = True, tokenKey = ":authority"}) ""
-- >>> toStaticEntry 8
-- Entry 42 (Token {tokenIx = 4, shouldBeIndexed = True, isPseudo = True, tokenKey = ":status"}) "200"
-- >>> toStaticEntry 50
-- Entry 37 (Token {tokenIx = 40, shouldBeIndexed = True, isPseudo = False, tokenKey = "Range"}) ""
toStaticEntry :: Index -> Entry
toStaticEntry :: Size -> Entry
toStaticEntry 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
- Size
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 (Size
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 = [
    (HeaderName
":authority", HeaderName
"")
  , (HeaderName
":method", HeaderName
"GET")
  , (HeaderName
":method", HeaderName
"POST")
  , (HeaderName
":path", HeaderName
"/")
  , (HeaderName
":path", HeaderName
"/index.html")
  , (HeaderName
":scheme", HeaderName
"http")
  , (HeaderName
":scheme", HeaderName
"https")
  , (HeaderName
":status", HeaderName
"200")
  , (HeaderName
":status", HeaderName
"204")
  , (HeaderName
":status", HeaderName
"206")
  , (HeaderName
":status", HeaderName
"304")
  , (HeaderName
":status", HeaderName
"400")
  , (HeaderName
":status", HeaderName
"404")
  , (HeaderName
":status", HeaderName
"500")
  , (HeaderName
"accept-charset", HeaderName
"")
  , (HeaderName
"accept-encoding", HeaderName
"gzip, deflate")
  , (HeaderName
"accept-language", HeaderName
"")
  , (HeaderName
"accept-ranges", HeaderName
"")
  , (HeaderName
"accept", HeaderName
"")
  , (HeaderName
"access-control-allow-origin", HeaderName
"")
  , (HeaderName
"age", HeaderName
"")
  , (HeaderName
"allow", HeaderName
"")
  , (HeaderName
"authorization", HeaderName
"")
  , (HeaderName
"cache-control", HeaderName
"")
  , (HeaderName
"content-disposition", HeaderName
"")
  , (HeaderName
"content-encoding", HeaderName
"")
  , (HeaderName
"content-language", HeaderName
"")
  , (HeaderName
"content-length", HeaderName
"")
  , (HeaderName
"content-location", HeaderName
"")
  , (HeaderName
"content-range", HeaderName
"")
  , (HeaderName
"content-type", HeaderName
"")
  , (HeaderName
"cookie", HeaderName
"")
  , (HeaderName
"date", HeaderName
"")
  , (HeaderName
"etag", HeaderName
"")
  , (HeaderName
"expect", HeaderName
"")
  , (HeaderName
"expires", HeaderName
"")
  , (HeaderName
"from", HeaderName
"")
  , (HeaderName
"host", HeaderName
"")
  , (HeaderName
"if-match", HeaderName
"")
  , (HeaderName
"if-modified-since", HeaderName
"")
  , (HeaderName
"if-none-match", HeaderName
"")
  , (HeaderName
"if-range", HeaderName
"")
  , (HeaderName
"if-unmodified-since", HeaderName
"")
  , (HeaderName
"last-modified", HeaderName
"")
  , (HeaderName
"link", HeaderName
"")
  , (HeaderName
"location", HeaderName
"")
  , (HeaderName
"max-forwards", HeaderName
"")
  , (HeaderName
"proxy-authenticate", HeaderName
"")
  , (HeaderName
"proxy-authorization", HeaderName
"")
  , (HeaderName
"range", HeaderName
"")
  , (HeaderName
"referer", HeaderName
"")
  , (HeaderName
"refresh", HeaderName
"")
  , (HeaderName
"retry-after", HeaderName
"")
  , (HeaderName
"server", HeaderName
"")
  , (HeaderName
"set-cookie", HeaderName
"")
  , (HeaderName
"strict-transport-security", HeaderName
"")
  , (HeaderName
"transfer-encoding", HeaderName
"")
  , (HeaderName
"user-agent", HeaderName
"")
  , (HeaderName
"vary", HeaderName
"")
  , (HeaderName
"via", HeaderName
"")
  , (HeaderName
"www-authenticate", HeaderName
"")
  ]