{-# LANGUAGE RankNTypes #-}
module Airship.Headers
( addResponseHeader
, modifyResponseHeaders
) where
import Airship.Types (Webmachine, ResponseState(..))
import Control.Monad.State.Class (modify)
import Network.HTTP.Types (ResponseHeaders, Header)
modifyResponseHeaders :: Monad m => (ResponseHeaders -> ResponseHeaders) -> Webmachine m ()
ResponseHeaders -> ResponseHeaders
f = (ResponseState -> ResponseState) -> Webmachine m ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ResponseState -> ResponseState
updateHeaders
where updateHeaders :: ResponseState -> ResponseState
updateHeaders rs :: ResponseState
rs@ResponseState{stateHeaders :: ResponseState -> ResponseHeaders
stateHeaders = ResponseHeaders
h} = ResponseState
rs { stateHeaders :: ResponseHeaders
stateHeaders = ResponseHeaders -> ResponseHeaders
f ResponseHeaders
h }
addResponseHeader :: Monad m => Header -> Webmachine m ()
Header
h = (ResponseHeaders -> ResponseHeaders) -> Webmachine m ()
forall (m :: * -> *).
Monad m =>
(ResponseHeaders -> ResponseHeaders) -> Webmachine m ()
modifyResponseHeaders (Header
h Header -> ResponseHeaders -> ResponseHeaders
forall a. a -> [a] -> [a]
:)