diff options
author | Joey Hess <joey@kitenet.net> | 2014-02-24 22:00:25 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-02-24 22:00:25 -0400 |
commit | 9f9f1decca4a06d81ce97b64ef1a06fda3b8efad (patch) | |
tree | 1f207862430497549281d510837dfcd9782f69af /Annex | |
parent | ba6f7e1e38063e4b338d6a7537b575411193b2b6 (diff) |
add UrlOptions sum type
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/Content.hs | 5 | ||||
-rw-r--r-- | Annex/Url.hs | 25 |
2 files changed, 22 insertions, 8 deletions
diff --git a/Annex/Content.hs b/Annex/Content.hs index 60edb4975..45e8e9d47 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -514,9 +514,8 @@ saveState nocommit = doSideAction $ do downloadUrl :: [Url.URLString] -> FilePath -> Annex Bool downloadUrl urls file = go =<< annexWebDownloadCommand <$> Annex.getGitConfig where - go Nothing = do - (headers, options) <- getHttpHeadersOptions - anyM (\u -> Url.withUserAgent $ Url.download u headers options file) urls + go Nothing = Url.withUrlOptions $ \uo -> + anyM (\u -> Url.download u file uo) urls go (Just basecmd) = liftIO $ anyM (downloadcmd basecmd) urls downloadcmd basecmd url = boolSystem "sh" [Param "-c", Param $ gencmd url basecmd] diff --git a/Annex/Url.hs b/Annex/Url.hs index 0401ffe07..397a7910b 100644 --- a/Annex/Url.hs +++ b/Annex/Url.hs @@ -1,13 +1,15 @@ -{- Url downloading, with git-annex user agent. +{- Url downloading, with git-annex user agent and configured http + - headers and wget/curl options. - - - Copyright 2013 Joey Hess <joey@kitenet.net> + - Copyright 2013-2014 Joey Hess <joey@kitenet.net> - - Licensed under the GNU GPL version 3 or higher. -} module Annex.Url ( module U, - withUserAgent, + withUrlOptions, + getUrlOptions, getUserAgent, ) where @@ -23,5 +25,18 @@ getUserAgent :: Annex (Maybe U.UserAgent) getUserAgent = Annex.getState $ Just . fromMaybe defaultUserAgent . Annex.useragent -withUserAgent :: (Maybe U.UserAgent -> IO a) -> Annex a -withUserAgent a = liftIO . a =<< getUserAgent +getUrlOptions :: Annex U.UrlOptions +getUrlOptions = U.UrlOptions + <$> getUserAgent + <*> headers + <*> options + where + headers = do + v <- annexHttpHeadersCommand <$> Annex.getGitConfig + case v of + Just cmd -> lines <$> liftIO (readProcess "sh" ["-c", cmd]) + Nothing -> annexHttpHeaders <$> Annex.getGitConfig + options = map Param . annexWebOptions <$> Annex.getGitConfig + +withUrlOptions :: (U.UrlOptions -> IO a) -> Annex a +withUrlOptions a = liftIO . a =<< getUrlOptions |