File: Url.hs

package info (click to toggle)
git-annex 6.20170101-1%2Bdeb9u2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 50,088 kB
  • sloc: haskell: 53,116; sh: 1,582; ansic: 341; makefile: 292; perl: 144
file content (58 lines) | stat: -rw-r--r-- 1,610 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{- Url downloading, with git-annex user agent and configured http
 - headers and wget/curl options.
 -
 - Copyright 2013-2014 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Annex.Url (
	module U,
	withUrlOptions,
	getUrlOptions,
	getUserAgent,
	httpAddressesUnlimited,
) where

import Annex.Common
import qualified Annex
import Utility.Url as U
import qualified Build.SysConfig as SysConfig

import qualified Data.Set as S

defaultUserAgent :: U.UserAgent
defaultUserAgent = "git-annex/" ++ SysConfig.packageversion

getUserAgent :: Annex (Maybe U.UserAgent)
getUserAgent = Annex.getState $ 
	Just . fromMaybe defaultUserAgent . Annex.useragent

getUrlOptions :: Annex U.UrlOptions
getUrlOptions = mkUrlOptions
	<$> getUserAgent
	<*> headers
	<*> options
	<*> urlschemes
  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
	urlschemes = ifM httpAddressesUnlimited
		( annexAllowedUrlSchemes <$> Annex.getGitConfig
		-- Don't allow any url schemes to be used when
		-- there's a limit on the allowed addresses, because
		-- there is no way to prevent curl or wget from
		-- redirecting to any address.
		, pure S.empty
		)

httpAddressesUnlimited :: Annex Bool
httpAddressesUnlimited =
	("all" == ) . annexAllowedHttpAddresses <$> Annex.getGitConfig

withUrlOptions :: (U.UrlOptions -> IO a) -> Annex a
withUrlOptions a = liftIO . a =<< getUrlOptions