@@ -80,13 +80,17 @@ const APP_ROOT = dirname(FileAccess.asFileUri('', require).fsPath);
80
80
81
81
export class WebClientServer {
82
82
83
+ private readonly _webExtensionResourceUrlTemplate : URI | undefined ;
84
+
83
85
constructor (
84
86
private readonly _connectionToken : ServerConnectionToken ,
85
87
@IServerEnvironmentService private readonly _environmentService : IServerEnvironmentService ,
86
88
@ILogService private readonly _logService : ILogService ,
87
89
@IRequestService private readonly _requestService : IRequestService ,
88
90
@IProductService private readonly _productService : IProductService ,
89
- ) { }
91
+ ) {
92
+ this . _webExtensionResourceUrlTemplate = this . _productService . extensionsGallery ?. resourceUrlTemplate ? URI . parse ( this . _productService . extensionsGallery . resourceUrlTemplate ) : undefined ;
93
+ }
90
94
91
95
async handle ( req : http . IncomingMessage , res : http . ServerResponse , parsedUrl : url . UrlWithParsedQuery ) : Promise < void > {
92
96
try {
@@ -149,20 +153,20 @@ export class WebClientServer {
149
153
* Handle extension resources
150
154
*/
151
155
private async _handleWebExtensionResource ( req : http . IncomingMessage , res : http . ServerResponse , parsedUrl : url . UrlWithParsedQuery ) : Promise < void > {
152
- if ( ! this . _productService . extensionsGallery ?. resourceUrlTemplate ) {
156
+ if ( ! this . _webExtensionResourceUrlTemplate ) {
153
157
return serveError ( req , res , 500 , 'No extension gallery service configured.' ) ;
154
158
}
155
159
156
160
// Strip `/web-extension-resource/` from the path
157
161
const normalizedPathname = decodeURIComponent ( parsedUrl . pathname ! ) ; // support paths that are uri-encoded (e.g. spaces => %20)
158
162
const path = normalize ( normalizedPathname . substr ( '/web-extension-resource/' . length ) ) ;
159
163
const uri = URI . parse ( path ) . with ( {
160
- scheme : this . _productService . extensionsGallery ?. resourceUrlTemplate ? URI . parse ( this . _productService . extensionsGallery . resourceUrlTemplate ) . scheme : 'https' ,
164
+ scheme : this . _webExtensionResourceUrlTemplate . scheme ,
161
165
authority : path . substring ( 0 , path . indexOf ( '/' ) ) ,
162
166
path : path . substring ( path . indexOf ( '/' ) + 1 )
163
167
} ) ;
164
168
165
- if ( this . _getResourceURLTemplateAuthority ( URI . parse ( this . _productService . extensionsGallery . resourceUrlTemplate ) ) !== this . _getResourceURLTemplateAuthority ( uri ) ) {
169
+ if ( this . _getResourceURLTemplateAuthority ( this . _webExtensionResourceUrlTemplate ) !== this . _getResourceURLTemplateAuthority ( uri ) ) {
166
170
return serveError ( req , res , 403 , 'Request Forbidden' ) ;
167
171
}
168
172
@@ -266,20 +270,19 @@ export class WebClientServer {
266
270
accessToken : this . _environmentService . args [ 'github-auth' ] ,
267
271
scopes : [ [ 'user:email' ] , [ 'repo' ] ]
268
272
} : undefined ;
269
- const resourceUrlTemplate = this . _productService . extensionsGallery ? URI . parse ( this . _productService . extensionsGallery . resourceUrlTemplate ) : undefined ;
270
273
const data = ( await util . promisify ( fs . readFile ) ( filePath ) ) . toString ( )
271
274
. replace ( '{{WORKBENCH_WEB_CONFIGURATION}}' , escapeAttribute ( JSON . stringify ( {
272
275
remoteAuthority,
273
276
_wrapWebWorkerExtHostInIframe,
274
277
developmentOptions : { enableSmokeTestDriver : this . _environmentService . driverHandle === 'web' ? true : undefined } ,
275
278
settingsSyncOptions : ! this . _environmentService . isBuilt && this . _environmentService . args [ 'enable-sync' ] ? { enabled : true } : undefined ,
276
279
productConfiguration : < Partial < IProductConfiguration > > {
277
- extensionsGallery : resourceUrlTemplate ? {
280
+ extensionsGallery : this . _webExtensionResourceUrlTemplate ? {
278
281
...this . _productService . extensionsGallery ,
279
- 'resourceUrlTemplate' : resourceUrlTemplate . with ( {
282
+ 'resourceUrlTemplate' : this . _webExtensionResourceUrlTemplate . with ( {
280
283
scheme : 'http' ,
281
284
authority : remoteAuthority ,
282
- path : `web-extension-resource/${ resourceUrlTemplate . authority } ${ resourceUrlTemplate . path } `
285
+ path : `web-extension-resource/${ this . _webExtensionResourceUrlTemplate . authority } ${ this . _webExtensionResourceUrlTemplate . path } `
283
286
} ) . toString ( true )
284
287
} : undefined
285
288
}
0 commit comments