Skip to content

Commit b657a50

Browse files
committed
formatting and clean up
1 parent b389ce3 commit b657a50

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/vs/server/node/webClientServer.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ export class WebClientServer {
9999
// always serve static requests, even without a token
100100
return this._handleStatic(req, res, parsedUrl);
101101
}
102-
if (/^\/extensionResource\//.test(pathname)) {
103-
// always serve static requests, even without a token
104-
return this._handleExtensionResource(req, res, parsedUrl);
105-
}
106102
if (pathname === '/') {
107103
// the token handling is done inside the handler
108104
return this._handleRoot(req, res, parsedUrl);
@@ -111,6 +107,10 @@ export class WebClientServer {
111107
// callback support
112108
return this._handleCallback(res);
113109
}
110+
if (/^\/extensionResource\//.test(pathname)) {
111+
// extension resource support
112+
return this._handleExtensionResource(req, res, parsedUrl);
113+
}
114114

115115
return serveError(req, res, 404, 'Not found.');
116116
} catch (error) {
@@ -143,9 +143,15 @@ export class WebClientServer {
143143
* Handle HTTP requests for /static/*
144144
*/
145145
private async _handleExtensionResource(req: http.IncomingMessage, res: http.ServerResponse, parsedUrl: url.UrlWithParsedQuery): Promise<void> {
146+
// Strip `/extensionResource/` from the path
146147
const normalizedPathname = decodeURIComponent(parsedUrl.pathname!); // support paths that are uri-encoded (e.g. spaces => %20)
147148
const path = normalize(normalizedPathname.substr('/extensionResource/'.length));
148-
const url = URI.parse(path).with({ scheme: 'https', authority: path.substring(0, path.indexOf('/')), path: path.substring(path.indexOf('/') + 1) });
149+
150+
const url = URI.parse(path).with({
151+
scheme: this._productService.extensionsGallery?.resourceUrlTemplate ? URI.parse(this._productService.extensionsGallery.resourceUrlTemplate).scheme : 'https',
152+
authority: path.substring(0, path.indexOf('/')),
153+
path: path.substring(path.indexOf('/') + 1)
154+
}).toString(true);
149155

150156
const headers: IHeaders = {};
151157
for (const header of req.rawHeaders) {
@@ -156,17 +162,11 @@ export class WebClientServer {
156162

157163
const context = await this._requestService.request({
158164
type: 'GET',
159-
url: url.toString(true),
165+
url,
160166
headers
161167
}, CancellationToken.None);
162168

163-
if (context.res.statusCode && context.res.statusCode !== 200) {
164-
this._logService.info(`Request to '${url.toString(true)}' failed with status code ${context.res.statusCode}`);
165-
throw new Error(`Server returned ${context.res.statusCode}`);
166-
}
167-
168-
const responseHeaders = context.res.headers;
169-
res.writeHead(200, responseHeaders);
169+
res.writeHead(context.res.statusCode || 500, context.res.headers);
170170
const buffer = await streamToBuffer(context.stream);
171171
return res.end(buffer.buffer);
172172
}
@@ -234,7 +234,14 @@ export class WebClientServer {
234234
developmentOptions: { enableSmokeTestDriver: this._environmentService.driverHandle === 'web' ? true : undefined },
235235
settingsSyncOptions: !this._environmentService.isBuilt && this._environmentService.args['enable-sync'] ? { enabled: true } : undefined,
236236
productConfiguration: <Partial<IProductConfiguration>>{
237-
extensionsGallery: resourceUrlTemplate ? { ...this._productService.extensionsGallery, 'resourceUrlTemplate': resourceUrlTemplate.with({ scheme: 'http', authority: remoteAuthority, path: `extensionResource/${resourceUrlTemplate.authority}${resourceUrlTemplate.path}` }).toString(true) } : undefined
237+
extensionsGallery: resourceUrlTemplate ? {
238+
...this._productService.extensionsGallery,
239+
'resourceUrlTemplate': resourceUrlTemplate.with({
240+
scheme: 'http',
241+
authority: remoteAuthority,
242+
path: `extensionResource/${resourceUrlTemplate.authority}${resourceUrlTemplate.path}`
243+
}).toString(true)
244+
} : undefined
238245
}
239246
})))
240247
.replace('{{WORKBENCH_AUTH_SESSION}}', () => authSessionInfo ? escapeAttribute(JSON.stringify(authSessionInfo)) : '');

0 commit comments

Comments
 (0)