git-annex/Annex/Url.hs

49 lines
1.3 KiB
Haskell
Raw Normal View History

2014-02-25 02:00:25 +00:00
{- Url downloading, with git-annex user agent and configured http
- headers and curl options.
-
- Copyright 2013-2018 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Annex.Url (
module U,
2014-02-25 02:00:25 +00:00
withUrlOptions,
getUrlOptions,
getUserAgent,
) where
import Annex.Common
import qualified Annex
import Utility.Url as U
import qualified BuildInfo
defaultUserAgent :: U.UserAgent
defaultUserAgent = "git-annex/" ++ BuildInfo.packageversion
getUserAgent :: Annex (Maybe U.UserAgent)
getUserAgent = Annex.getState $
Just . fromMaybe defaultUserAgent . Annex.useragent
getUrlOptions :: Annex U.UrlOptions
getUrlOptions = Annex.getState Annex.urloptions >>= \case
Just uo -> return uo
Nothing -> do
uo <- mk
Annex.changeState $ \s -> s
{ Annex.urloptions = Just uo }
return uo
2014-02-25 02:00:25 +00:00
where
mk = mkUrlOptions
<$> getUserAgent
<*> headers
<*> options
<*> liftIO (U.newManager U.managerSettings)
2017-12-05 19:00:50 +00:00
headers = annexHttpHeadersCommand <$> Annex.getGitConfig >>= \case
Just cmd -> lines <$> liftIO (readProcess "sh" ["-c", cmd])
Nothing -> annexHttpHeaders <$> Annex.getGitConfig
2014-02-25 02:00:25 +00:00
options = map Param . annexWebOptions <$> Annex.getGitConfig
withUrlOptions :: (U.UrlOptions -> Annex a) -> Annex a
withUrlOptions a = a =<< getUrlOptions