Skip to content

Commit 2227b06

Browse files
authored
Add proxy URI enviroment variable (#37)
This can be used by extensions or in the terminal.
1 parent 69a6ce4 commit 2227b06

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

src/vs/platform/remote/browser/remoteAuthorityResolverService.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
2020
private readonly _connectionToken: string | undefined;
2121
private readonly _connectionTokens: Map<string, string>;
2222

23-
constructor(connectionToken: string | undefined, resourceUriProvider: ((uri: URI) => URI) | undefined) {
23+
/**
24+
* Add proxy endpoint template.
25+
* @author coder
26+
*/
27+
constructor(connectionToken: string | undefined, resourceUriProvider: ((uri: URI) => URI) | undefined, private readonly proxyEndpointUrlTemplate?: string) {
2428
super();
2529
this._cache = new Map<string, ResolverResult>();
2630
this._connectionToken = connectionToken;
@@ -59,12 +63,21 @@ export class RemoteAuthorityResolverService extends Disposable implements IRemot
5963

6064
private _doResolveAuthority(authority: string): ResolverResult {
6165
const connectionToken = this._connectionTokens.get(authority) || this._connectionToken;
66+
/**
67+
* Add VSCODE_PROXY_URI to the environment.
68+
* @author coder
69+
*/
70+
const options = {}
71+
if (this.proxyEndpointUrlTemplate) {
72+
const proxyUrl = new URL(this.proxyEndpointUrlTemplate, window.location.href);
73+
options.extensionHostEnv = { VSCODE_PROXY_URI: decodeURIComponent(proxyUrl.toString()) }
74+
}
6275
if (authority.indexOf(':') >= 0) {
6376
const pieces = authority.split(':');
64-
return { authority: { authority, host: pieces[0], port: parseInt(pieces[1], 10), connectionToken } };
77+
return { authority: { authority, host: pieces[0], port: parseInt(pieces[1], 10), connectionToken }, options };
6578
}
6679
const port = (/^https:/.test(window.location.href) ? 443 : 80);
67-
return { authority: { authority, host: authority, port: port, connectionToken } };
80+
return { authority: { authority, host: authority, port: port, connectionToken }, options };
6881
}
6982

7083
_clearResolvedAuthority(authority: string): void {

src/vs/server/webClientServer.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,11 @@ export class WebClientServer {
320320
// Endpoints
321321
base,
322322
logoutEndpointUrl: base + '/logout',
323+
proxyEndpointUrlTemplate: base + '/proxy/{{port}}',
323324
webEndpointUrl: vscodeBase + '/static',
324325
webEndpointUrlTemplate: vscodeBase + '/static',
325326
webviewContentExternalBaseUrlTemplate: vscodeBase + '/webview/{{uuid}}/',
326-
updateUrl: base + '/update/check'
327+
updateUrl: base + '/update/check',
327328
},
328329
folderUri: (workspacePath && isFolder) ? transformer.transformOutgoing(URI.file(workspacePath)) : undefined,
329330
workspaceUri: (workspacePath && !isFolder) ? transformer.transformOutgoing(URI.file(workspacePath)) : undefined,

src/vs/workbench/browser/web.main.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,11 @@ class BrowserMain extends Disposable {
179179

180180
// Remote
181181
const connectionToken = environmentService.options.connectionToken || getCookieValue('vscode-tkn');
182-
const remoteAuthorityResolverService = new RemoteAuthorityResolverService(connectionToken, this.configuration.resourceUriProvider);
182+
/**
183+
* Add proxy URL template to the resolver.
184+
* @author coder
185+
*/
186+
const remoteAuthorityResolverService = new RemoteAuthorityResolverService(connectionToken, this.configuration.resourceUriProvider, this.configuration.productConfiguration?.proxyEndpointUrlTemplate);
183187
serviceCollection.set(IRemoteAuthorityResolverService, remoteAuthorityResolverService);
184188

185189
// Signing

src/vs/workbench/contrib/terminal/common/terminalEnvironment.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,11 @@ export function createTerminalEnvironment(
388388

389389
// Sanitize the environment, removing any undesirable VS Code and Electron environment
390390
// variables
391-
sanitizeProcessEnvironment(env, 'VSCODE_IPC_HOOK_CLI');
391+
/**
392+
* Do not remove the proxy URI.
393+
* @author coder
394+
*/
395+
sanitizeProcessEnvironment(env, 'VSCODE_IPC_HOOK_CLI', 'VSCODE_PROXY_URI');
392396

393397
// Merge config (settings) and ShellLaunchConfig environments
394398
mergeEnvironments(env, allowedEnvFromConfig);

0 commit comments

Comments
 (0)