Skip to content

Commit

Permalink
Use unredirected headers
Browse files Browse the repository at this point in the history
  • Loading branch information
gemenerik committed Aug 12, 2024
1 parent f6c4c21 commit fdef495
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tools/build/package
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ def _read_manifest(path, platform, versions):


def _download_artifact(uri) -> io.BytesIO:
headers = {}

# Add auth headers if the github token is available, on the build servers it is, but when running locally it is not.
# Some operations do not require authentication but we do it anyway to avoid API call rate problems
request = urllib.request.Request(url=uri)
request.add_unredirected_header(key="Accept", val="application/vnd.github+json")
if 'GITHUB_TOKEN' in os.environ:
GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
headers = {'Authorization': f'token {GITHUB_TOKEN}'}
request.add_unredirected_header(key="Authorization", val=f"Bearer {GITHUB_TOKEN}")
print(' Downloading with authorization')
else:
print(' Downloading without authorization')

req = urllib.request.Request(uri, headers=headers)
with urllib.request.urlopen(req) as response:
with urllib.request.urlopen(request) as response:
data = response.read()
assert (data)
return io.BytesIO(data)
Expand Down

0 comments on commit fdef495

Please sign in to comment.