@@ -59,9 +59,16 @@ class Recipe(metaclass=RecipeMeta):
5959 if you want.
6060 '''
6161
62- _github_access_token = None
63- '''Used to access a private git repository. Specify the github-supplied
64- access token in order to download the private repository files.
62+ _download_headers = None
63+ '''Add additional headers used when downloading the package, typically
64+ for authorization purposes.
65+
66+ Specified as an array of tuples:
67+ [("header name", "header value")]
68+
69+ For example, when downloading from a private
70+ github repository, you can specify the following:
71+ [('Authorization', 'token <your personal access token>'), ('Accept', 'application/vnd.github+json')]
6572 '''
6673
6774 _version = None
@@ -176,9 +183,9 @@ def versioned_url(self):
176183 return self .url .format (version = self .version )
177184
178185 @property
179- def github_access_token (self ):
180- key = "GITHUB_ACCESS_TOKEN_ " + self .name
181- return environ .get (key , self ._github_access_token )
186+ def download_headers (self ):
187+ key = "DOWNLOAD_HEADERS_ " + self .name
188+ return environ .get (key , self ._download_headers )
182189
183190 def download_file (self , url , target , cwd = None ):
184191 """
@@ -215,8 +222,8 @@ def report_hook(index, blksize, size):
215222 # jqueryui.com returns a 403 w/ the default user agent
216223 # Mozilla/5.0 doesnt handle redirection for liblzma
217224 url_opener .addheaders = [('User-agent' , 'Wget/1.0' )]
218- if self .github_access_token :
219- url_opener .addheaders += [( 'Authorization' , f'token { self .github_access_token } ' ), ( 'Accept' , 'application/vnd.github+json' )]
225+ if self .download_headers :
226+ url_opener .addheaders += self .download_headers
220227 urlretrieve (url , target , report_hook )
221228 except OSError as e :
222229 attempts += 1
0 commit comments