Skip to content

Commit

Permalink
Support specifying User-Agent for downloads in an env var
Browse files Browse the repository at this point in the history
So that we can distinguish CI downloads from real downloads.

Ticket: ENT-7919
Changelog: CFBS_USER_AGENT environment variable can now be used to set User-Agent for file downloads
  • Loading branch information
vpodzime committed Apr 8, 2022
1 parent 9bf6a85 commit 4c90b19
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 4c90b19

Please sign in to comment.