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