Skip to content

Commit

Permalink
fix: Upload release failed. Response status: 401 Unauthorized
Browse files Browse the repository at this point in the history
Close #1385
  • Loading branch information
develar committed Apr 16, 2017
1 parent a3c4a9e commit 257a7dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
4 changes: 3 additions & 1 deletion docs/Auto Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do

| Name | Type | Description |
| --- | --- | --- |
| autoDownload = <code>true</code>| <code>boolean</code> | <a name="AppUpdater-autoDownload"></a>Automatically download an update when it is found. |
| autoDownload = <code>true</code>| <code>boolean</code> | <a name="AppUpdater-autoDownload"></a>Whether to automatically download an update when it is found. |
| allowPrerelease| <code>boolean</code> | <a name="AppUpdater-allowPrerelease"></a>*GitHub provider only.* Whether to allow update to pre-release versions. Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`.<br><br>If `true`, downgrade will be allowed (`allowDowngrade` will be set to `true`). |
| allowDowngrade| <code>boolean</code> | <a name="AppUpdater-allowDowngrade"></a>Whether to allow version downgrade (when a user from the beta channel wants to go back to the stable channel). Defaults to `true` if application version contains prerelease components (e.g. `0.12.1-alpha.1`, here `alpha` is a prerelease component), otherwise `false`. |
| requestHeaders| <code>[RequestHeaders](electron-builder-http#RequestHeaders)</code> \| <code>null</code> | <a name="AppUpdater-requestHeaders"></a>The request headers. |
| logger = <code>(&lt;any&gt;global).__test_app ? null : console</code>| <code>[Logger](#Logger)</code> \| <code>null</code> | <a name="AppUpdater-logger"></a>The logger. You can pass [electron-log](https://github.com/megahertz/electron-log), [winston](https://github.com/winstonjs/winston) or another logger with the following interface: `{ info(), warn(), error() }`. Set it to `null` if you would like to disable a logging feature. |
| signals = <code>new UpdaterSignal(this)</code>| <code>[UpdaterSignal](#UpdaterSignal)</code> | <a name="AppUpdater-signals"></a>For type safety you can use signals, e.g. `autoUpdater.signals.updateDownloaded(() => {})` instead of `autoUpdater.on('update-available', () => {})` |
Expand Down
16 changes: 3 additions & 13 deletions packages/electron-builder-http/src/httpExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
}

const newUrl = parseUrl(redirectUrl)
this.doApiRequest(<REQUEST_OPTS>removeAuthHeader(Object.assign({}, options, newUrl)), cancellationToken, requestProcessor, redirectCount)
this.doApiRequest(<REQUEST_OPTS>Object.assign({}, options, newUrl), cancellationToken, requestProcessor, redirectCount)
.then(resolve)
.catch(reject)
return
Expand Down Expand Up @@ -161,11 +161,11 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
if (redirectUrl != null) {
if (redirectCount < this.maxRedirects) {
const parsedUrl = parseUrl(redirectUrl)
this.doDownload(removeAuthHeader(Object.assign({}, requestOptions, {
this.doDownload(Object.assign({}, requestOptions, {
hostname: parsedUrl.hostname,
path: parsedUrl.path,
port: parsedUrl.port == null ? undefined : parsedUrl.port
})), destination, redirectCount++, options, callback, onCancel)
}), destination, redirectCount++, options, callback, onCancel)
}
else {
callback(new Error(`Too many redirects (> ${this.maxRedirects})`))
Expand Down Expand Up @@ -310,14 +310,4 @@ export function dumpRequestOptions(options: RequestOptions): string {
safe.headers.authorization = "<skipped>"
}
return JSON.stringify(safe, null, 2)
}

// requestOptions should be cloned already, modified in place
function removeAuthHeader(requestOptions: RequestOptions): RequestOptions {
// github redirect to amazon s3 - avoid error "Only one auth mechanism allowed"
if (requestOptions.headers != null && (requestOptions.hostname || "").includes(".amazonaws.") && requestOptions.headers.Authorization != null && requestOptions.headers.Authorization.startsWith("token ")) {
requestOptions.headers = Object.assign({}, requestOptions.headers)
delete requestOptions.headers.Authorization
}
return requestOptions
}

0 comments on commit 257a7dd

Please sign in to comment.