Skip to content

Commit

Permalink
fix: fix and issue with media types due to improper header management
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinWilkinson committed May 15, 2024
1 parent 77c8d26 commit 6864c7f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions GitHubClients/ReleaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,23 @@ export class ReleaseClient extends GitHubClient {

const url = `https://api.github.com/repos/${this.ownerName}/${this.repoName}/releases/assets/${assetId}`;

// Get the current accept header to set it back after the download
const acceptHeader = this.getHeader("Accept") ?? "";

// Change the default 'Accept' header from 'application/vnd.github+json' to 'application/octet-stream'
// This is required for download as a file
this.updateOrAddHeader("Accept", "application/octet-stream");

const response = await this.requestGET(url);

// Reset the `Accept` header back to the original value
this.updateOrAddHeader("Accept", acceptHeader);

if (response.status === GitHubHttpStatusCodes.Unauthorized) {
throw new AuthError();
} else if (response.status !== GitHubHttpStatusCodes.OK) {
const errorMsg = `The asset with the id '${assetId}' could not be downloaded.`;

throw new ReleaseError(errorMsg);
}

Expand Down

0 comments on commit 6864c7f

Please sign in to comment.