Skip to content

Commit

Permalink
Don't recalculate domain suffix list per-request.
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiddens committed Aug 11, 2015
1 parent 92535a0 commit 37bd26f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions http-client/Network/HTTP/Client/Manager.hs
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ envHelper name eh = do
env <- getEnvironment
let lenv = Map.fromList $ map (first $ T.toLower . T.pack) env
lookupEnvVar n = lookup (T.unpack n) env <|> Map.lookup n lenv
noProxyDomains = domainSuffixes (lookupEnvVar "no_proxy")
case lookupEnvVar name of
Nothing -> return noEnvProxy
Just "" -> return noEnvProxy
Expand Down Expand Up @@ -543,7 +544,7 @@ envHelper name eh = do

Just $ (Proxy (S8.pack $ U.uriRegName auth) port, muserpass)
return $ \req ->
if host req `hasDomainSuffixIn` lookupEnvVar "no_proxy"
if host req `hasDomainSuffixIn` noProxyDomains
then noEnvProxy req
else maybe id (uncurry applyBasicProxyAuth) muserpass
req { proxy = Just p }
Expand All @@ -553,7 +554,7 @@ envHelper name eh = do
EHUseProxy p -> \req -> req { proxy = Just p }
prefixed s | S8.head s == '.' = s
| otherwise = S8.cons '.' s
domainSuffixes no_proxy = [ prefixed $ S8.dropWhile (== ' ') suffix | suffix <- S8.split ',' (S8.pack (map toLower no_proxy)), not (S8.null suffix)]
hasDomainSuffixIn _ Nothing = False
hasDomainSuffixIn _ (Just "") = False
hasDomainSuffixIn host (Just no_proxy) = any (`S8.isSuffixOf` prefixed (S8.map toLower host)) (domainSuffixes no_proxy)
domainSuffixes Nothing = []
domainSuffixes (Just "") = []
domainSuffixes (Just no_proxy) = [prefixed $ S8.dropWhile (== ' ') suffix | suffix <- S8.split ',' (S8.pack (map toLower no_proxy)), not (S8.null suffix)]
hasDomainSuffixIn host = any (`S8.isSuffixOf` prefixed (S8.map toLower host))

0 comments on commit 37bd26f

Please sign in to comment.