Interface change for consistency: rewriteURL is idempotent on addresses with no matching rules.

master
vi 2014-08-24 23:57:55 +08:00
parent 663f9b61dc
commit 6d12745fc9
2 changed files with 4 additions and 3 deletions

View File

@ -11,7 +11,7 @@ used secure HTTP connections when possible."
λ: :m + Data.HTTPSEverywhere.Rules Network.URI
λ: let Just eff = parseURI "http://www.eff.org/document/eff-and-aclu-amicus-brief-klayman"
λ: rewriteURL eff
Just https://www.eff.org/document/eff-and-aclu-amicus-brief-klayman
https://www.eff.org/document/eff-and-aclu-amicus-brief-klayman
λ: :m + Web.Cookie Network.HTTP.Client Data.Time.Clock Control.Applicative
λ: :set -XOverloadedStrings
λ: (now, req) <- (,) <$> getCurrentTime <*> parseUrl "https://github.com"

View File

@ -6,6 +6,7 @@ module Data.HTTPSEverywhere.Rules (
import Prelude hiding (null, head)
import Control.Lens ((<&>),(&))
import Data.Bool (bool)
import Data.Maybe (fromMaybe)
import Network.HTTP.Client (Cookie)
import Network.URI (URI)
import Pipes ((>->))
@ -13,8 +14,8 @@ import Pipes.Prelude (head, null)
import Control.Monad (join)
import Data.HTTPSEverywhere.Rules.Internal (getRulesetsMatching, havingRulesThatTrigger, havingCookieRulesThatTrigger, setSecureFlag)
rewriteURL :: URI -> IO (Maybe URI)
rewriteURL url = getRulesetsMatching url >-> havingRulesThatTrigger url & head <&> join
rewriteURL :: URI -> IO URI
rewriteURL url = getRulesetsMatching url >-> havingRulesThatTrigger url & head <&> fromMaybe url . join
rewriteCookie :: URI -> Cookie -> IO Cookie
rewriteCookie url cookie = null producer <&> setSecureFlag cookie `bool` cookie