Skip to content

Commit

Permalink
Read proxy config from the environment
Browse files Browse the repository at this point in the history
Reads the environment variable `http_proxy` as the proxy config if the
setting `"http.proxy"` is not set.

Closes redhat-developer#764

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Aug 17, 2022
1 parent 9eb434d commit b77c24e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/settings/proxySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ export function getProxySettingsAsJVMArgs(proxySettings: ProxySettings): string
* @param proxySettings the proxy settings to convert into environment variables
* @returns the proxy settings as environment variables for LemMinX
*/
export function getProxySettingsAsEnvironmentVariables(proxySettings: ProxySettings): any {
const proxyEnv: any = {};
export function getProxySettingsAsEnvironmentVariables(proxySettings: ProxySettings): Record<string, string> {
// process.env inherits from Object, so it's okay to do so here as well
const proxyEnv: Record<string, string> = {};

proxyEnv['HTTP_PROXY_HOST'] = proxySettings.host;
proxyEnv['HTTP_PROXY_PORT'] = proxySettings.port;
Expand Down Expand Up @@ -164,7 +165,13 @@ const JVM_PROXY_PASS = 'http.proxyPassword';
* @returns the address of the proxy
*/
function getProxyAddress(): string {
return workspace.getConfiguration('http').get('proxy', undefined);
const fromSettings = workspace.getConfiguration('http').get('proxy', undefined);
if (fromSettings) {
return fromSettings;
}
// VS Code allows you to set up the proxy using the environment variables http_proxy and https_proxy
// Use this as fallback if the `"http.proxy"` setting isn't set
return process.env['http_proxy'];
}

/**
Expand Down

0 comments on commit b77c24e

Please sign in to comment.