2014-02-25 02:00:25 +00:00
|
|
|
{- Url downloading, with git-annex user agent and configured http
|
2018-04-06 21:00:46 +00:00
|
|
|
- headers and curl options.
|
2013-09-28 18:35:21 +00:00
|
|
|
-
|
2018-04-04 19:00:51 +00:00
|
|
|
- Copyright 2013-2018 Joey Hess <id@joeyh.name>
|
2013-09-28 18:35:21 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.Url (
|
|
|
|
module U,
|
2014-02-25 02:00:25 +00:00
|
|
|
withUrlOptions,
|
2018-04-04 19:15:12 +00:00
|
|
|
getUrlOptions,
|
2013-09-28 18:35:21 +00:00
|
|
|
getUserAgent,
|
|
|
|
) where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2013-09-28 18:35:21 +00:00
|
|
|
import qualified Annex
|
|
|
|
import Utility.Url as U
|
2017-12-14 16:46:57 +00:00
|
|
|
import qualified BuildInfo
|
2013-09-28 18:35:21 +00:00
|
|
|
|
|
|
|
defaultUserAgent :: U.UserAgent
|
2017-12-14 16:46:57 +00:00
|
|
|
defaultUserAgent = "git-annex/" ++ BuildInfo.packageversion
|
2013-09-28 18:35:21 +00:00
|
|
|
|
|
|
|
getUserAgent :: Annex (Maybe U.UserAgent)
|
|
|
|
getUserAgent = Annex.getState $
|
|
|
|
Just . fromMaybe defaultUserAgent . Annex.useragent
|
|
|
|
|
2018-04-04 19:15:12 +00:00
|
|
|
getUrlOptions :: Annex U.UrlOptions
|
|
|
|
getUrlOptions = Annex.getState Annex.urloptions >>= \case
|
|
|
|
Just uo -> return uo
|
2018-04-04 19:00:51 +00:00
|
|
|
Nothing -> do
|
|
|
|
uo <- mk
|
|
|
|
Annex.changeState $ \s -> s
|
|
|
|
{ Annex.urloptions = Just uo }
|
2018-04-04 19:15:12 +00:00
|
|
|
return uo
|
2014-02-25 02:00:25 +00:00
|
|
|
where
|
2018-04-04 19:00:51 +00:00
|
|
|
mk = mkUrlOptions
|
|
|
|
<$> getUserAgent
|
|
|
|
<*> headers
|
|
|
|
<*> options
|
2018-04-04 19:15:12 +00:00
|
|
|
<*> 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
|
2018-04-04 19:15:12 +00:00
|
|
|
|
|
|
|
withUrlOptions :: (U.UrlOptions -> Annex a) -> Annex a
|
|
|
|
withUrlOptions a = a =<< getUrlOptions
|