https-everywhere-rules/src/Data/HTTPSEverywhere/Rules.hs

26 lines
886 B
Haskell
Raw Normal View History

module Data.HTTPSEverywhere.Rules (
rewriteURL,
rewriteCookie
) where
2014-08-10 01:16:57 +02:00
import Prelude hiding (take, null)
import Control.Applicative ((<$))
import Control.Lens ((<&>))
import Data.Bool (bool)
import Network.HTTP.Client (Cookie)
import Network.URI (URI)
2014-08-10 01:16:57 +02:00
import Pipes (runEffect, (>->))
import Pipes.Prelude (take, null)
2014-08-10 01:16:57 +02:00
import Data.HTTPSEverywhere.Rules.Internal (getRulesetsMatching, havingRulesThatTrigger, havingCookieRulesThatTrigger, setSecureFlag)
rewriteURL :: URI -> IO (Maybe URI)
2014-08-10 01:16:57 +02:00
rewriteURL url = runEffect
$ (Nothing <$ getRulesetsMatching url)
>-> (Nothing <$ havingRulesThatTrigger url)
>-> (Nothing <$ take 1)
rewriteCookie :: URI -> Cookie -> IO Cookie
2014-08-10 01:16:57 +02:00
rewriteCookie url cookie = null producer <&> setSecureFlag cookie `bool` cookie
where producer = getRulesetsMatching url >-> (() <$ havingCookieRulesThatTrigger cookie)