module Network.Wai.Middleware.StripHeaders
( stripHeader
, stripHeaders
, stripHeaderIf
, stripHeadersIf
) where
import Network.Wai (Middleware, Request, modifyResponse, mapResponseHeaders, ifRequest)
import Network.Wai.Internal (Response)
import Data.ByteString (ByteString)
import qualified Data.CaseInsensitive as CI
stripHeader :: ByteString -> (Response -> Response)
stripHeader h = mapResponseHeaders (filter (\ hdr -> fst hdr /= CI.mk h))
stripHeaders :: [ByteString] -> (Response -> Response)
stripHeaders hs =
let hnames = map CI.mk hs
in mapResponseHeaders (filter (\ hdr -> fst hdr `notElem` hnames))
stripHeaderIf :: ByteString -> (Request -> Bool) -> Middleware
stripHeaderIf h rpred =
ifRequest rpred (modifyResponse $ stripHeader h)
stripHeadersIf :: [ByteString] -> (Request -> Bool) -> Middleware
stripHeadersIf hs rpred
= ifRequest rpred (modifyResponse $ stripHeaders hs)