module Network.Wai.Middleware.AddHeaders
( addHeaders
) where
import Network.HTTP.Types (Header)
import Network.Wai (Middleware, modifyResponse, mapResponseHeaders)
import Network.Wai.Internal (Response(..))
import Data.ByteString (ByteString)
import qualified Data.CaseInsensitive as CI
import Control.Arrow (first)
addHeaders :: [(ByteString, ByteString)] -> Middleware
[(ByteString, ByteString)]
h = (Response -> Response) -> Middleware
modifyResponse ((Response -> Response) -> Middleware)
-> (Response -> Response) -> Middleware
forall a b. (a -> b) -> a -> b
$ [Header] -> Response -> Response
addHeaders' (((ByteString, ByteString) -> Header)
-> [(ByteString, ByteString)] -> [Header]
forall a b. (a -> b) -> [a] -> [b]
map ((ByteString -> CI ByteString) -> (ByteString, ByteString) -> Header
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first ByteString -> CI ByteString
forall s. FoldCase s => s -> CI s
CI.mk) [(ByteString, ByteString)]
h)
addHeaders' :: [Header] -> Response -> Response
[Header]
h = ([Header] -> [Header]) -> Response -> Response
mapResponseHeaders (\[Header]
hs -> [Header]
h [Header] -> [Header] -> [Header]
forall a. [a] -> [a] -> [a]
++ [Header]
hs)