2014-08-09 22:23:41 +02:00
|
|
|
module Data.HTTPSEverywhere.Rules (
|
|
|
|
rewriteURL,
|
|
|
|
rewriteCookie
|
|
|
|
) where
|
|
|
|
|
2014-08-24 06:40:06 +02:00
|
|
|
import Prelude hiding (null, head)
|
|
|
|
import Control.Lens ((<&>),(&))
|
2014-08-10 01:16:57 +02:00
|
|
|
import Data.Bool (bool)
|
2014-08-09 22:23:41 +02:00
|
|
|
import Network.HTTP.Client (Cookie)
|
2014-08-10 21:32:49 +02:00
|
|
|
import Network.URI (URI)
|
2014-08-24 06:40:06 +02:00
|
|
|
import Pipes ((>->))
|
|
|
|
import Pipes.Prelude (head, null)
|
|
|
|
import Control.Monad (join)
|
2014-08-10 01:16:57 +02:00
|
|
|
import Data.HTTPSEverywhere.Rules.Internal (getRulesetsMatching, havingRulesThatTrigger, havingCookieRulesThatTrigger, setSecureFlag)
|
2014-08-09 22:23:41 +02:00
|
|
|
|
2014-08-10 21:32:49 +02:00
|
|
|
rewriteURL :: URI -> IO (Maybe URI)
|
2014-08-24 06:40:06 +02:00
|
|
|
rewriteURL url = getRulesetsMatching url >-> havingRulesThatTrigger url & head <&> join
|
2014-08-09 22:23:41 +02:00
|
|
|
|
2014-08-10 21:32:49 +02:00
|
|
|
rewriteCookie :: URI -> Cookie -> IO Cookie
|
2014-08-10 01:16:57 +02:00
|
|
|
rewriteCookie url cookie = null producer <&> setSecureFlag cookie `bool` cookie
|
2014-08-24 06:40:06 +02:00
|
|
|
where producer = getRulesetsMatching url >-> havingCookieRulesThatTrigger cookie
|