Skip to content

Commit

Permalink
implement marketplace cdn fallback logic
Browse files Browse the repository at this point in the history
related to #10180
  • Loading branch information
joaomoreno committed Aug 17, 2016
1 parent 2c39e55 commit 1449af5
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
import pkg from 'vs/platform/package';
import product from 'vs/platform/product';
import { isValidExtensionVersion } from 'vs/platform/extensions/node/extensionValidator';
import * as url from 'url';

interface IRawGalleryExtensionFile {
assetType: string;
Expand Down Expand Up @@ -351,8 +352,18 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
return this._getAsset({ url });
}

/**
* Always try with the `redirect=true` query string.
* If that does not return 200, try without it.
*/
private _getAsset(options: IRequestOptions): TPromise<IRequestContext> {
return this.requestService.request(options);
const parsedUrl = url.parse(options.url, true);
parsedUrl.search = undefined;
parsedUrl.query['redirect'] = 'true';

return this.requestService.request(assign({}, options, { url: url.format(parsedUrl) }))
.then(context => context.res.statusCode !== 200 && TPromise.wrapError('expected 200'))
.then(null, () => this.requestService.request(options));
}

private getLastValidExtensionVersion(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): TPromise<IRawGalleryExtensionVersion> {
Expand Down

0 comments on commit 1449af5

Please sign in to comment.