HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulesnap-core-1.0.5.1Haskell2010

Snap.Types.Headers

An opaque data type for HTTP headers. Intended to be imported qualified, i.e:

import           Snap.Types.Headers (Headers)
import qualified Snap.Types.Headers as H

foo :: Headers
foo = H.empty
Contents
  1. Headers type
  2. Headers creation
  3. Predicates
  4. Lookup
  5. Adding/setting headers
  6. Deleting
  7. Traversal
  8. Lists
Synopsis
  • Packagesnap-core-1.0.5.1
  • Exports18
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceHeaders.hs

Headers type

newtypenewtype Headers

A key-value map that represents a collection of HTTP header fields. Keys are case-insensitive.

Instances2Show, HasHeaders

Headers creation

Predicates

Lookup

Adding/setting headers

Insert a key-value pair into the headers map. If the key already exists in the map, the values are catenated with ", ".

Example:

ghci> :set -XOverloadedStrings
ghci> let hdrs = H.insert "Accept" "text/plain" $ H.empty
ghci> hdrs
H {unH = [("accept","text/plain")]}
ghci> H.insert "Accept" "text/html" $ hdrs
H {unH = [("accept","text/plain,text/html")]}

Insert a key-value pair into the headers map, without checking whether the header already exists. The key must be already case-folded, or none of the lookups will work!

Example:

ghci> :set -XOverloadedStrings
ghci> let hdrs = H.unsafeInsert "accept" "text/plain" $ H.empty
ghci> hdrs
H {unH = [("accept","text/plain")]}
ghci> let hdrs' = H.unsafeInsert "accept" "text/html" $ hdrs
ghci> hdrs'
H {unH = [("accept","text/html"), ("accept","text/plain")]}
ghci> H.lookup "accept" hdrs'
Just "text/html"

Set the value of a HTTP header field to a given value, replacing the old value.

Example:

ghci> :set -XOverloadedStrings
ghci> H.set "accept" "text/plain" $ H.empty
H {unH = [("accept","text/plain")]}
ghci> H.set "accept" "text/html" $ H.fromList [("Accept", "text/plain")]
H {unH = [("accept","text/html")]}

Deleting

Traversal

valuefoldl' :: (a -> CI ByteString -> ByteString -> a) -> a -> Headers -> a

Strict left fold over all key-value pairs in the headers map.

Example:

ghci> :set -XOverloadedStrings
ghci> import Data.Monoid
ghci> let hdrs = H.fromList [("Accept", "text/plain"), ("Accept", "text/html")]
ghci> let f (cntr, acc) _ val = (cntr+1, val <> ";" <> acc)
ghci> H.foldl' f (0, "") hdrs
(2,"text/html;text/plain;")
valuefoldr :: (CI ByteString -> ByteString -> a -> a) -> a -> Headers -> a

Right fold over all key-value pairs in the headers map.

Example:

ghci> :set -XOverloadedStrings
ghci> import Data.Monoid
ghci> let hdrs = H.fromList [("Accept", "text/plain"), ("Accept", "text/html")]
ghci> let f _ val (cntr, acc) = (cntr+1, val <> ";" <> acc)
ghci> H.foldr f (0, "") hdrs
(2,"text/plain;text/html;")

Lists