Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Rudy Flores <[email protected]>
  • Loading branch information
rudyflores committed Dec 10, 2024
1 parent 00df0a3 commit bf6db6b
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/imperative/src/rest/src/client/ProxySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,17 @@ export class ProxySettings {
*/
public static getProxyAgent(session: ISession): Agent | undefined {
const proxySetting = this.getProxySettings(session);
const proxyUrl = proxySetting.proxyUrl;
const proxyAuthorizationHeader = proxySetting.authSetting;
const proxyOptions = {} as ProxyOptions;
const authHeader = ProxySettings.getProxyAuthHeader(proxySetting);
if(authHeader) {
proxyOptions.headers = authHeader;

Check warning on line 51 in packages/imperative/src/rest/src/client/ProxySettings.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/rest/src/client/ProxySettings.ts#L51

Added line #L51 was not covered by tests
}
if (proxySetting?.protocol === HTTP_PROTOCOL) {
const proxyAgentOptions = proxyAuthorizationHeader
? { headers: { 'Proxy-Authorization': proxyAuthorizationHeader } }
: undefined;
return new HttpProxyAgent(proxyUrl, proxyAgentOptions);
return new HttpProxyAgent(proxySetting.proxyUrl, proxyOptions);
}
if (proxySetting?.protocol === HTTPS_PROTOCOL) {
const proxyAgentOptions = {
rejectUnauthorized: session.rejectUnauthorized ?? true,
headers: { 'Proxy-Authorization': proxyAuthorizationHeader }
};
return new HttpsProxyAgent(proxyUrl, proxyAgentOptions);
proxyOptions.rejectUnauthorized = session.rejectUnauthorized ?? true;
return new HttpsProxyAgent(proxySetting.proxyUrl, proxyOptions);
}
}

Expand Down Expand Up @@ -96,6 +93,12 @@ export class ProxySettings {
return false;
}

private static getProxyAuthHeader(proxySetting: ProxySetting): { [key: string]: string } | undefined {
return proxySetting.authSetting
? { 'Proxy-Authorization': proxySetting.authSetting }

Check warning on line 98 in packages/imperative/src/rest/src/client/ProxySettings.ts

View check run for this annotation

Codecov / codecov/patch

packages/imperative/src/rest/src/client/ProxySettings.ts#L98

Added line #L98 was not covered by tests
: undefined;
}

/**
* Parses environment variables for proxy servers.
* @private
Expand Down Expand Up @@ -190,3 +193,8 @@ interface ProxySetting {
protocol: HTTP_PROTOCOL_CHOICES,
authSetting?: string
}

interface ProxyOptions {
headers?: { [key: string]: string },
rejectUnauthorized?: boolean
}

0 comments on commit bf6db6b

Please sign in to comment.