Skip to content

Commit

Permalink
Merge pull request #106 from vpodzime/master-ci_user_agent
Browse files Browse the repository at this point in the history
Support specifying User-Agent for downloads in an env var
  • Loading branch information
olehermanse authored Apr 11, 2022
2 parents 9bf6a85 + 4c90b19 commit 5be3e65
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cfbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,14 @@ def fetch_url(url, target, checksum=None):
else:
sha = hashlib.sha1()

headers = dict()
user_agent = os.environ.get("CFBS_USER_AGENT")
if user_agent is not None:
headers["User-Agent"] = user_agent
request = urllib.request.Request(url, headers=headers)
try:
with open(target, "wb") as f:
with urllib.request.urlopen(url) as u:
with urllib.request.urlopen(request) as u:
if not (200 <= u.status <= 300):
raise FetchError("Failed to fetch '%s': %s" % (url, u.reason))
done = False
Expand Down

0 comments on commit 5be3e65

Please sign in to comment.