@@ -167,18 +167,22 @@ export class VscodeHttpProvider extends HttpProvider {
167167 }
168168
169169 private async getRoot ( request : http . IncomingMessage , route : Route ) : Promise < HttpResponse > {
170+ const remoteAuthority = request . headers . host as string
170171 const settings = await this . settings . read ( )
171- const startPath = await this . getFirstValidPath ( [
172- { url : route . query . workspace , workspace : true } ,
173- { url : route . query . folder , workspace : false } ,
174- settings . lastVisited ,
175- this . args . _ && this . args . _ . length > 0 ? { url : this . urlify ( this . args . _ [ 0 ] ) } : undefined ,
176- ] )
172+ const startPath = await this . getFirstValidPath (
173+ [
174+ { url : route . query . workspace , workspace : true } ,
175+ { url : route . query . folder , workspace : false } ,
176+ settings . lastVisited ,
177+ this . args . _ && this . args . _ . length > 0 ? { url : this . args . _ [ 0 ] } : undefined ,
178+ ] ,
179+ remoteAuthority
180+ )
177181 const [ response , options ] = await Promise . all ( [
178182 await this . getUtf8Resource ( this . rootPath , `src/node/vscode/workbench${ ! this . isDev ? "-build" : "" } .html` ) ,
179183 this . initialize ( {
180184 args : this . args ,
181- remoteAuthority : request . headers . host as string ,
185+ remoteAuthority,
182186 startPath,
183187 } ) ,
184188 ] )
@@ -217,7 +221,8 @@ export class VscodeHttpProvider extends HttpProvider {
217221 * workspace or a directory otherwise.
218222 */
219223 private async getFirstValidPath (
220- startPaths : Array < { url ?: string | string [ ] ; workspace ?: boolean } | undefined >
224+ startPaths : Array < { url ?: string | string [ ] ; workspace ?: boolean } | undefined > ,
225+ remoteAuthority : string
221226 ) : Promise < StartPath | undefined > {
222227 for ( let i = 0 ; i < startPaths . length ; ++ i ) {
223228 const startPath = startPaths [ i ]
@@ -226,14 +231,23 @@ export class VscodeHttpProvider extends HttpProvider {
226231 }
227232 const paths = typeof startPath . url === "string" ? [ startPath . url ] : startPath . url || [ ]
228233 for ( let j = 0 ; j < paths . length ; ++ j ) {
229- const u = url . parse ( paths [ j ] )
234+ const uri = url . parse ( paths [ j ] )
230235 try {
231- if ( ! u . pathname ) {
236+ if ( ! uri . pathname ) {
232237 throw new Error ( `${ paths [ j ] } is not a valid URL` )
233238 }
234- const stat = await fs . stat ( u . pathname )
239+ const stat = await fs . stat ( uri . pathname )
235240 if ( typeof startPath . workspace === "undefined" || startPath . workspace !== stat . isDirectory ( ) ) {
236- return { url : u . href , workspace : ! stat . isDirectory ( ) }
241+ return {
242+ url : url . format ( {
243+ protocol : uri . protocol || "vscode-remote" ,
244+ hostname : remoteAuthority . split ( ":" ) [ 0 ] ,
245+ port : remoteAuthority . split ( ":" ) [ 1 ] ,
246+ pathname : uri . pathname ,
247+ slashes : true ,
248+ } ) ,
249+ workspace : ! stat . isDirectory ( ) ,
250+ }
237251 }
238252 } catch ( error ) {
239253 logger . warn ( error . message )
@@ -242,8 +256,4 @@ export class VscodeHttpProvider extends HttpProvider {
242256 }
243257 return undefined
244258 }
245-
246- private urlify ( p : string ) : string {
247- return "vscode-remote://host" + path . resolve ( p )
248- }
249259}
0 commit comments