Replace Axios calls with HttpClient (#22417)

* replace axios calls with httpClient

* add latest files

* fix url
This commit is contained in:
Christopher Suh
2023-03-23 13:47:25 -07:00
committed by GitHub
parent 57c35ca255
commit 00897fc513
7 changed files with 525 additions and 2 deletions

View File

@@ -4,8 +4,19 @@
*--------------------------------------------------------------------------------------------*/
import * as loc from './localizedConstants';
import * as vscode from 'vscode';
import * as constants from './constants';
import { AzureRegion, azureResource } from 'azurecore';
import { AppContext } from './appContext';
import { HttpClient } from './account-provider/auths/httpClient';
import { parse } from 'url';
import { getProxyAgentOptions } from './proxy';
import { HttpsProxyAgentOptions } from 'https-proxy-agent';
const configProxy = 'proxy';
const configProxyStrictSSL = 'proxyStrictSSL';
const configProxyAuthorization = 'proxyAuthorization';
/**
* Converts a region value (@see AzureRegion) into the localized Display Name
@@ -125,6 +136,9 @@ export function getResourceTypeDisplayName(type: string): string {
}
return type;
}
function getHttpConfiguration(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration(constants.httpConfigSectionName);
}
export function getResourceTypeIcon(appContext: AppContext, type: string): string {
switch (type) {
@@ -145,3 +159,23 @@ export function getResourceTypeIcon(appContext: AppContext, type: string): strin
}
return '';
}
export function getProxyEnabledHttpClient(): HttpClient {
const proxy = <string>getHttpConfiguration().get(configProxy);
const strictSSL = getHttpConfiguration().get(configProxyStrictSSL, true);
const authorization = getHttpConfiguration().get(configProxyAuthorization);
const url = parse(proxy);
let agentOptions = getProxyAgentOptions(url, proxy, strictSSL);
if (authorization && url.protocol === 'https:') {
let httpsAgentOptions = agentOptions as HttpsProxyAgentOptions;
httpsAgentOptions!.headers = Object.assign(httpsAgentOptions!.headers || {}, {
'Proxy-Authorization': authorization
});
agentOptions = httpsAgentOptions;
}
return new HttpClient(proxy, agentOptions);
}