Skip to content

Commit 362a2ca

Browse files
committed
cache resourceUrlTemplate Uri
1 parent 56291ed commit 362a2ca

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/vs/server/node/webClientServer.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,17 @@ const APP_ROOT = dirname(FileAccess.asFileUri('', require).fsPath);
8080

8181
export class WebClientServer {
8282

83+
private readonly _webExtensionResourceUrlTemplate: URI | undefined;
84+
8385
constructor(
8486
private readonly _connectionToken: ServerConnectionToken,
8587
@IServerEnvironmentService private readonly _environmentService: IServerEnvironmentService,
8688
@ILogService private readonly _logService: ILogService,
8789
@IRequestService private readonly _requestService: IRequestService,
8890
@IProductService private readonly _productService: IProductService,
89-
) { }
91+
) {
92+
this._webExtensionResourceUrlTemplate = this._productService.extensionsGallery?.resourceUrlTemplate ? URI.parse(this._productService.extensionsGallery.resourceUrlTemplate) : undefined;
93+
}
9094

9195
async handle(req: http.IncomingMessage, res: http.ServerResponse, parsedUrl: url.UrlWithParsedQuery): Promise<void> {
9296
try {
@@ -149,20 +153,20 @@ export class WebClientServer {
149153
* Handle extension resources
150154
*/
151155
private async _handleWebExtensionResource(req: http.IncomingMessage, res: http.ServerResponse, parsedUrl: url.UrlWithParsedQuery): Promise<void> {
152-
if (!this._productService.extensionsGallery?.resourceUrlTemplate) {
156+
if (!this._webExtensionResourceUrlTemplate) {
153157
return serveError(req, res, 500, 'No extension gallery service configured.');
154158
}
155159

156160
// Strip `/web-extension-resource/` from the path
157161
const normalizedPathname = decodeURIComponent(parsedUrl.pathname!); // support paths that are uri-encoded (e.g. spaces => %20)
158162
const path = normalize(normalizedPathname.substr('/web-extension-resource/'.length));
159163
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,
161165
authority: path.substring(0, path.indexOf('/')),
162166
path: path.substring(path.indexOf('/') + 1)
163167
});
164168

165-
if (this._getResourceURLTemplateAuthority(URI.parse(this._productService.extensionsGallery.resourceUrlTemplate)) !== this._getResourceURLTemplateAuthority(uri)) {
169+
if (this._getResourceURLTemplateAuthority(this._webExtensionResourceUrlTemplate) !== this._getResourceURLTemplateAuthority(uri)) {
166170
return serveError(req, res, 403, 'Request Forbidden');
167171
}
168172

@@ -266,20 +270,19 @@ export class WebClientServer {
266270
accessToken: this._environmentService.args['github-auth'],
267271
scopes: [['user:email'], ['repo']]
268272
} : undefined;
269-
const resourceUrlTemplate = this._productService.extensionsGallery ? URI.parse(this._productService.extensionsGallery.resourceUrlTemplate) : undefined;
270273
const data = (await util.promisify(fs.readFile)(filePath)).toString()
271274
.replace('{{WORKBENCH_WEB_CONFIGURATION}}', escapeAttribute(JSON.stringify({
272275
remoteAuthority,
273276
_wrapWebWorkerExtHostInIframe,
274277
developmentOptions: { enableSmokeTestDriver: this._environmentService.driverHandle === 'web' ? true : undefined },
275278
settingsSyncOptions: !this._environmentService.isBuilt && this._environmentService.args['enable-sync'] ? { enabled: true } : undefined,
276279
productConfiguration: <Partial<IProductConfiguration>>{
277-
extensionsGallery: resourceUrlTemplate ? {
280+
extensionsGallery: this._webExtensionResourceUrlTemplate ? {
278281
...this._productService.extensionsGallery,
279-
'resourceUrlTemplate': resourceUrlTemplate.with({
282+
'resourceUrlTemplate': this._webExtensionResourceUrlTemplate.with({
280283
scheme: 'http',
281284
authority: remoteAuthority,
282-
path: `web-extension-resource/${resourceUrlTemplate.authority}${resourceUrlTemplate.path}`
285+
path: `web-extension-resource/${this._webExtensionResourceUrlTemplate.authority}${this._webExtensionResourceUrlTemplate.path}`
283286
}).toString(true)
284287
} : undefined
285288
}

0 commit comments

Comments
 (0)