Modern resolve.

trie
vi 2018-06-28 00:08:17 -06:00
parent 00d2341394
commit b93ff6bbb6
7 changed files with 51 additions and 56 deletions

View File

@ -13,7 +13,7 @@ license-file:
author:
vi
maintainer:
vi@zalora.com
vi@computational.law
category:
Data
build-type:
@ -628,22 +628,21 @@ library
Data.Text.ICU.Extras,
Paths_https_everywhere_rules
build-depends:
base >= 4.7 && < 4.10,
attoparsec >= 0.12 && < 0.14,
directory >= 1.2 && < 1.4,
errors >= 1.4 && < 2.2,
filepath >= 1.3 && < 1.5,
functor-infix >= 0.0 && < 0.1,
http-client >= 0.3 && < 0.6,
lens >= 4.3 && < 4.16,
mtl >= 2.2 && < 2.3,
network >= 2.6 && < 2.7,
network-uri >= 2.6 && < 2.7,
pipes >= 4.1 && < 4.4,
string-conversions >= 0.3 && < 0.5,
taggy-lens >= 0.1 && < 0.2,
text >= 1.1 && < 1.3,
text-icu >= 0.6 && < 0.8
base,
attoparsec,
directory,
errors,
filepath,
http-client,
lens,
mtl,
network,
network-uri,
pipes,
string-conversions,
taggy-lens,
text,
text-icu
hs-source-dirs:
src
default-language:
@ -655,23 +654,22 @@ test-suite spec
type:
exitcode-stdio-1.0
build-depends:
base >= 4.7 && < 4.10,
attoparsec >= 0.12 && < 0.14,
directory >= 1.2 && < 1.4,
errors >= 1.4 && < 2.2,
filepath >= 1.3 && < 1.5,
functor-infix >= 0.0 && < 0.1,
hspec >= 2.0 && < 2.5,
http-client >= 0.3 && < 0.6,
lens >= 4.3 && < 4.16,
mtl >= 2.2 && < 2.3,
network >= 2.6 && < 2.7,
network-uri >= 2.6 && < 2.7,
pipes >= 4.1 && < 4.4,
string-conversions >= 0.3 && < 0.5,
taggy-lens >= 0.1 && < 0.2,
text >= 1.1 && < 1.3,
text-icu >= 0.6 && < 0.8,
base,
attoparsec,
directory,
errors,
filepath,
hspec,
http-client,
lens,
mtl,
network,
network-uri,
pipes,
string-conversions,
taggy-lens,
text,
text-icu,
https-everywhere-rules
main-is:
Spec.hs
@ -709,7 +707,7 @@ executable redirect-proxy
RedirectProxy.hs
if flag(build-examples)
build-depends:
base >= 4.7 && < 4.10,
base,
bytestring,
http-proxy,
http-types,

View File

@ -7,7 +7,6 @@ module Data.HTTPSEverywhere.Rules (
import Prelude hiding (null, head)
import Data.Bool (bool)
import Data.Functor.Infix ((<$$>), (<$$$>))
import Network.HTTP.Client (Cookie)
import Network.URI (URI)
import Pipes ((>->))
@ -19,11 +18,11 @@ rewriteURL' :: Monad m => [RuleSet] -> URI -> m (Maybe URI)
rewriteURL' rs url = head $ getRulesetsMatching rs url >-> havingRulesThatTrigger url
rewriteURL :: [RuleSet] -> (URI -> Maybe URI)
rewriteURL = runIdentity <$$> rewriteURL'
rewriteURL = fmap runIdentity <$> rewriteURL'
rewriteCookie' :: Monad m => [RuleSet] -> URI -> Cookie -> m (Maybe Cookie)
rewriteCookie' rs url cookie = Just (setSecureFlag cookie) `bool` Nothing <$> null producer
where producer = getRulesetsMatching rs url >-> havingCookieRulesThatTrigger cookie
rewriteCookie :: [RuleSet] -> URI -> (Cookie -> Maybe Cookie)
rewriteCookie = runIdentity <$$$> rewriteCookie'
rewriteCookie = fmap (fmap runIdentity) <$> rewriteCookie'

View File

@ -19,7 +19,6 @@ import Control.Applicative ((<*>), (<$>))
import Control.Lens ((&))
import Control.Monad ((<=<), join)
import Data.Bool (bool)
import Data.Functor.Infix ((<$$>))
import Data.List (find)
import Data.Maybe (isJust)
import Network.HTTP.Client (Cookie(..))
@ -33,7 +32,7 @@ import Data.HTTPSEverywhere.Rules.Internal.Types (RuleSet(..), Target(..), Exclu
getRulesets' :: Producer RuleSet IO ()
getRulesets' = lift Raw.getRules
>>= flip (for . each) (flip (for . each) yield <=< lift . (parseRuleSets <$$> Raw.getRule))
>>= flip (for . each) (flip (for . each) yield <=< lift . (fmap parseRuleSets <$> Raw.getRule))
getRulesets :: IO [RuleSet]
getRulesets = toListM getRulesets'
@ -53,19 +52,19 @@ havingCookieRulesThatTrigger cookie = flip hasTriggeringCookieRuleOn cookie <$>
hasTargetMatching :: RuleSet -> URI -> Bool
hasTargetMatching ruleset url = getTargets ruleset <*> [url] & or
where getTargets = getTarget <$$> ruleSetTargets
where getTargets = fmap getTarget <$> ruleSetTargets
hasExclusionMatching :: RuleSet -> URI -> Bool
hasExclusionMatching ruleset url = getExclusions ruleset <*> [url] & or
where getExclusions = getExclusion <$$> ruleSetExclusions
where getExclusions = fmap getExclusion <$> ruleSetExclusions
hasTriggeringRuleOn :: RuleSet -> URI -> Maybe URI -- Nothing ~ False
hasTriggeringRuleOn ruleset url = getRules ruleset <*> [url] & find isJust & join
where getRules = getRule <$$> ruleSetRules
where getRules = fmap getRule <$> ruleSetRules
hasTriggeringCookieRuleOn :: RuleSet -> Cookie -> Bool
hasTriggeringCookieRuleOn ruleset cookie = getCookieRules ruleset <*> [cookie] & or
where getCookieRules = getCookieRule <$$> ruleSetCookieRules
where getCookieRules = fmap getCookieRule <$> ruleSetCookieRules
setSecureFlag :: Cookie -> Cookie
setSecureFlag cookie = cookie { cookie_secure_only = True }

View File

@ -17,7 +17,6 @@ import Control.Monad (join)
import Control.Monad.State (State, evalState, modify', gets)
import Data.Bifunctor (bimap)
import Data.Bool (bool)
import Data.Functor.Infix ((<$$>))
import Data.Maybe (catMaybes)
import Data.String.Conversions (cs)
import qualified Data.Text as Strict (Text)
@ -31,7 +30,7 @@ import Data.HTTPSEverywhere.Rules.Internal.Types (RuleSet(..), Target(..), Rule(
import Data.Text.ICU.Extras (match, findAndReplace)
parseRuleSets :: Lazy.Text -> [RuleSet]
parseRuleSets = catMaybes <$$> toListOf $ html . allNamed (only "ruleset") . to parseRuleSet
parseRuleSets = fmap catMaybes <$> toListOf $ html . allNamed (only "ruleset") . to parseRuleSet
parseRuleSet :: Element -> Maybe RuleSet
parseRuleSet xml = xml ^. attr "name" <&> \ruleSetName -> do
@ -65,7 +64,7 @@ parseRule element = do
return . Rule $ join . fmap (parseURI . cs) . substitute . cs . show
parseExclusion :: Strict.Text -> Maybe Exclusion
parseExclusion = Exclusion . (. cs . show) <$$> match
parseExclusion = fmap (Exclusion . (. cs . show)) <$> match
parseCookieRule :: Element -> Maybe CookieRule
parseCookieRule element = CookieRule <$> do

View File

@ -4,7 +4,6 @@ module Data.HTTPSEverywhere.Rules.Internal.Raw (
) where
import Prelude hiding (readFile)
import Data.Functor.Infix ((<$$>))
import Data.Text.Lazy (Text)
import Data.Text.Lazy.IO (readFile)
import System.Directory (getDirectoryContents)
@ -16,8 +15,8 @@ getRule :: FilePath -> IO Text
getRule = readFile
getRules :: IO [FilePath]
getRules = getDataFileName [] >>= filter isXML <$$> getAbsoluteDirectoryContents
getRules = getDataFileName [] >>= fmap (filter isXML) <$> getAbsoluteDirectoryContents
where isXML = (== ".xml") . takeExtension
getAbsoluteDirectoryContents :: FilePath -> IO [FilePath]
getAbsoluteDirectoryContents x = combine x <$$> getDirectoryContents x
getAbsoluteDirectoryContents x = fmap (combine x) <$> getDirectoryContents x

View File

@ -17,7 +17,6 @@ import Control.Applicative ((<$>), (<*>), (*>), (<|>))
import Control.Error (hush)
import Data.Attoparsec.Text (Parser, char, digit, takeWhile1, string, many', parseOnly)
import Data.Char (digitToInt)
import Data.Functor.Infix ((<$$>), (<&>))
import Data.Maybe (isJust)
import Data.Monoid (Monoid(mappend, mconcat))
import Data.Text (Text)
@ -27,7 +26,7 @@ regex :: Text -> Maybe Regex
regex = hush . regex' []
match :: Text -> Maybe (Text -> Bool)
match = (isJust <$$> find) <$$> regex
match = fmap (fmap isJust <$> find) <$> regex
findAndReplace :: Text -> Text -> Maybe (Text -> Maybe Text)
findAndReplace pattern replacement = (.)
@ -41,7 +40,7 @@ data Segment = Reference Int | Literal Text deriving (Show, Eq)
-- JavaScript admits at most nine capture groups, so this is the correct
-- (and likely intended) interpretation.
parseReference :: Parser Segment
parseReference = char '$' *> digit <&> Reference . digitToInt
parseReference = (Reference . digitToInt) <$> (char '$' *> digit)
parseLiteral :: Parser Segment
parseLiteral = Literal <$> takeWhile1 (/= '$')

View File

@ -1,6 +1,8 @@
packages:
- .
extra-deps:
- functor-infix-0.0.5
- http-proxy-0.1.0.5
resolver: lts-8.24
- taggy-0.2.1
- taggy-lens-0.1.2
- http-proxy-0.1.0.6
resolver: lts-11.14
allow-newer: true