@@ -99,10 +99,6 @@ export class WebClientServer {
99
99
// always serve static requests, even without a token
100
100
return this . _handleStatic ( req , res , parsedUrl ) ;
101
101
}
102
- if ( / ^ \/ e x t e n s i o n R e s o u r c e \/ / . test ( pathname ) ) {
103
- // always serve static requests, even without a token
104
- return this . _handleExtensionResource ( req , res , parsedUrl ) ;
105
- }
106
102
if ( pathname === '/' ) {
107
103
// the token handling is done inside the handler
108
104
return this . _handleRoot ( req , res , parsedUrl ) ;
@@ -111,6 +107,10 @@ export class WebClientServer {
111
107
// callback support
112
108
return this . _handleCallback ( res ) ;
113
109
}
110
+ if ( / ^ \/ e x t e n s i o n R e s o u r c e \/ / . test ( pathname ) ) {
111
+ // extension resource support
112
+ return this . _handleExtensionResource ( req , res , parsedUrl ) ;
113
+ }
114
114
115
115
return serveError ( req , res , 404 , 'Not found.' ) ;
116
116
} catch ( error ) {
@@ -143,9 +143,15 @@ export class WebClientServer {
143
143
* Handle HTTP requests for /static/*
144
144
*/
145
145
private async _handleExtensionResource ( req : http . IncomingMessage , res : http . ServerResponse , parsedUrl : url . UrlWithParsedQuery ) : Promise < void > {
146
+ // Strip `/extensionResource/` from the path
146
147
const normalizedPathname = decodeURIComponent ( parsedUrl . pathname ! ) ; // support paths that are uri-encoded (e.g. spaces => %20)
147
148
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 ) ;
149
155
150
156
const headers : IHeaders = { } ;
151
157
for ( const header of req . rawHeaders ) {
@@ -156,17 +162,11 @@ export class WebClientServer {
156
162
157
163
const context = await this . _requestService . request ( {
158
164
type : 'GET' ,
159
- url : url . toString ( true ) ,
165
+ url,
160
166
headers
161
167
} , CancellationToken . None ) ;
162
168
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 ) ;
170
170
const buffer = await streamToBuffer ( context . stream ) ;
171
171
return res . end ( buffer . buffer ) ;
172
172
}
@@ -234,7 +234,14 @@ export class WebClientServer {
234
234
developmentOptions : { enableSmokeTestDriver : this . _environmentService . driverHandle === 'web' ? true : undefined } ,
235
235
settingsSyncOptions : ! this . _environmentService . isBuilt && this . _environmentService . args [ 'enable-sync' ] ? { enabled : true } : undefined ,
236
236
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
238
245
}
239
246
} ) ) )
240
247
. replace ( '{{WORKBENCH_AUTH_SESSION}}' , ( ) => authSessionInfo ? escapeAttribute ( JSON . stringify ( authSessionInfo ) ) : '' ) ;
0 commit comments