@@ -21,7 +21,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
2121import pkg from 'vs/platform/node/package' ;
2222import product from 'vs/platform/node/product' ;
2323import { isVersionValid } from 'vs/platform/extensions/node/extensionValidator' ;
24- import { getCommonHTTPHeaders } from 'vs/platform/environment/node/http ' ;
24+ import { IEnvironmentService } from 'vs/platform/environment/common/environment ' ;
2525
2626interface IRawGalleryExtensionFile {
2727 assetType : string ;
@@ -276,16 +276,21 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
276276
277277 private extensionsGalleryUrl : string ;
278278
279- private readonly commonHTTPHeaders : TPromise < { [ key : string ] : string ; } > ;
279+ private readonly commonHTTPHeaders : { [ key : string ] : string ; } ;
280280
281281 constructor (
282282 @IRequestService private requestService : IRequestService ,
283+ @IEnvironmentService private environmentService : IEnvironmentService ,
283284 @ITelemetryService private telemetryService : ITelemetryService ,
284285 @IConfigurationService private configurationService : IConfigurationService
285286 ) {
286287 const config = product . extensionsGallery ;
287288 this . extensionsGalleryUrl = config && config . serviceUrl ;
288- this . commonHTTPHeaders = getCommonHTTPHeaders ( ) ;
289+ this . commonHTTPHeaders = {
290+ 'X-Market-Client-Id' : `VSCode ${ pkg . version } ` ,
291+ 'User-Agent' : `VSCode ${ pkg . version } ` ,
292+ 'X-Market-User-Id' : this . environmentService . machineUUID
293+ } ;
289294 }
290295
291296 private api ( path = '' ) : string {
@@ -296,10 +301,6 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
296301 return ! ! this . extensionsGalleryUrl ;
297302 }
298303
299- getRequestHeaders ( ) : TPromise < { [ key : string ] : string ; } > {
300- return this . commonHTTPHeaders ;
301- }
302-
303304 query ( options : IQueryOptions = { } ) : TPromise < IPager < IGalleryExtension > > {
304305 if ( ! this . isEnabled ( ) ) {
305306 return TPromise . wrapError < IPager < IGalleryExtension > > ( new Error ( 'No extension gallery service configured.' ) ) ;
@@ -541,26 +542,23 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
541542
542543 private getAsset ( asset : IGalleryExtensionAsset , options : IRequestOptions = { } ) : TPromise < IRequestContext > {
543544 const baseOptions = { type : 'GET' } ;
545+ const headers = assign ( { } , this . commonHTTPHeaders , options . headers || { } ) ;
546+ options = assign ( { } , options , baseOptions , { headers } ) ;
544547
545- return this . commonHTTPHeaders . then ( headers => {
546- headers = assign ( { } , headers , options . headers || { } ) ;
547- options = assign ( { } , options , baseOptions , { headers } ) ;
548+ const firstOptions = assign ( { } , options , { url : asset . uri } ) ;
548549
549- const firstOptions = assign ( { } , options , { url : asset . uri } ) ;
550+ return this . requestService . request ( firstOptions )
551+ . then ( context => context . res . statusCode === 200 ? context : TPromise . wrapError < IRequestContext > ( new Error ( 'expected 200' ) ) )
552+ . then ( null , err => {
553+ this . telemetryService . publicLog ( 'galleryService:requestError' , { cdn : true , message : getErrorMessage ( err ) } ) ;
554+ this . telemetryService . publicLog ( 'galleryService:cdnFallback' , { url : asset . uri } ) ;
550555
551- return this . requestService . request ( firstOptions )
552- . then ( context => context . res . statusCode === 200 ? context : TPromise . wrapError < IRequestContext > ( new Error ( 'expected 200' ) ) )
553- . then ( null , err => {
554- this . telemetryService . publicLog ( 'galleryService:requestError' , { cdn : true , message : getErrorMessage ( err ) } ) ;
555- this . telemetryService . publicLog ( 'galleryService:cdnFallback' , { url : asset . uri } ) ;
556-
557- const fallbackOptions = assign ( { } , options , { url : asset . fallbackUri } ) ;
558- return this . requestService . request ( fallbackOptions ) . then ( null , err => {
559- this . telemetryService . publicLog ( 'galleryService:requestError' , { cdn : false , message : getErrorMessage ( err ) } ) ;
560- return TPromise . wrapError < IRequestContext > ( err ) ;
561- } ) ;
556+ const fallbackOptions = assign ( { } , options , { url : asset . fallbackUri } ) ;
557+ return this . requestService . request ( fallbackOptions ) . then ( null , err => {
558+ this . telemetryService . publicLog ( 'galleryService:requestError' , { cdn : false , message : getErrorMessage ( err ) } ) ;
559+ return TPromise . wrapError < IRequestContext > ( err ) ;
562560 } ) ;
563- } ) ;
561+ } ) ;
564562 }
565563
566564 private getLastValidExtensionVersion ( extension : IRawGalleryExtension , versions : IRawGalleryExtensionVersion [ ] ) : TPromise < IRawGalleryExtensionVersion > {
0 commit comments