You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't include HTTP headers from GitHub API request in redirected artifact download request
In the use case where the "arduino/report-size-deltas" action is ran from a GitHub Actions workflow triggered by a
`schedule` event, it downloads the sketches report file from a workflow artifact.
The GitHub REST API is used to perform this artifact download. The artifact download process is:
1. Action sends request to `/repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}` endpoint
2. API responds with HTTP 302 status
3. Action sends request to temporary file download URL provided by the API response
4. Artifact file is downloaded
The API request at step (1) must be authenticated using a GitHub access token. This token is passed via the
`Authorization` HTTP header in the request.
No authentication is required for the download request at step (3).
The `urllib.request` Python module is used to perform the HTTP requests. By default, this module passes the headers from
the original request to the redirect request.
Although these headers were superfluous, they didn't affect the download request when the target artifact was of the v1
format generated by version 3.x and earlier of the "actions/upload-artifact" action. A new v2 artifact format was
introduced in the 4.0.0 release of the "actions/upload-artifact" action. Previously, the request at step (3) of the
artifact download procedure would fail when the target artifact had the v2 format:
```
urllib.error.HTTPError: HTTP Error 400: Authentication information is not given in the correct format. Check the value of Authorization header.
Error: HTTPError: HTTP Error 400: Authentication information is not given in the correct format. Check the value of Authorization header.
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidAuthenticationInfo</Code><Message>Authentication information is not given in the correct format. Check the value of Authorization header.
RequestId:1f13170a-001e-0076-5f5d-4e8d15000000
Time:2024-01-24T00:35:22.8264229Z</Message></Error>
```
The cause of the failure was the inclusion of the `Authorization` HTTP header in the download request. The
`urllib.request` Python module can be configured to pass a header in the original request but not in the redirected
request by defining the header via the `Request.add_unredirected_header` method instead of in the `Request`
instantiation. This provides compatibility for using the action with v2 format artifacts.
0 commit comments