From 6d12745fc93809625a93655ab9bbfd244394cea2 Mon Sep 17 00:00:00 2001 From: vi Date: Sun, 24 Aug 2014 23:57:55 +0800 Subject: [PATCH] Interface change for consistency: rewriteURL is idempotent on addresses with no matching rules. --- README.md | 2 +- src/Data/HTTPSEverywhere/Rules.hs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d8cf634..4e17e9a 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/src/Data/HTTPSEverywhere/Rules.hs b/src/Data/HTTPSEverywhere/Rules.hs index c7d51bd..915389c 100644 --- a/src/Data/HTTPSEverywhere/Rules.hs +++ b/src/Data/HTTPSEverywhere/Rules.hs @@ -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