Skip to content

Commit d49e268

Browse files
authored
[core] delay loading of NO_PROXY (Azure#14880)
until when ProxyPolicy is created
1 parent 0b9d82b commit d49e268

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

sdk/core/core-http/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.2.5 (Unreleased)
44

5+
- Delay loading of NO_PROXY environment variable until when request pipeline is being created. This fixes [issue 14873](https://github.com/Azure/azure-sdk-for-js/issues/14873)
56

67
## 1.2.4 (2021-03-30)
78

sdk/core/core-http/src/policies/proxyPolicy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { getEnvironmentValue } from "../util/utils";
1717
/**
1818
* @internal
1919
*/
20-
export const noProxyList: string[] = loadNoProxy();
20+
export const noProxyList: string[] = [];
21+
22+
let noProxyListLoaded: boolean = false;
2123
const byPassedList: Map<string, boolean> = new Map();
2224

2325
function loadEnvironmentProxyValue(): string | undefined {
@@ -70,6 +72,7 @@ function isBypassed(uri: string): boolean | undefined {
7072
*/
7173
export function loadNoProxy(): string[] {
7274
const noProxy = getEnvironmentValue(Constants.NO_PROXY);
75+
noProxyListLoaded = true;
7376
if (noProxy) {
7477
return noProxy
7578
.split(",")
@@ -103,6 +106,9 @@ export function proxyPolicy(proxySettings?: ProxySettings): RequestPolicyFactory
103106
if (!proxySettings) {
104107
proxySettings = getDefaultProxySettings();
105108
}
109+
if (!noProxyListLoaded) {
110+
noProxyList.push(...loadNoProxy());
111+
}
106112
return {
107113
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
108114
return new ProxyPolicy(nextPolicy, options, proxySettings!);

sdk/core/core-rest-pipeline/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## 1.1.0-beta.1 (Unreleased)
44

5+
- Rewrote `bearerTokenAuthenticationPolicy` to use a new backend that refreshes tokens only when they're about to expire and not multiple times before. This is based on a similar fix implemented on `@azure/core-http@1.2.4` ([PR with the changes](https://github.com/Azure/azure-sdk-for-js/pull/14223)). This fixes the issue: [13369](https://github.com/Azure/azure-sdk-for-js/issues/13369).
56
- Add a new `bearerTokenChallengeAuthenticationPolicy` that provides a skeleton of handling challenge-based authorization. There are two extensible points: `authorizeRequest` and `authorizeRequestOnChallenge` callbacks.
67
- `authorizeRequest` allows customizing the policy to alter how it authorizes a request before sending it. By default when no callbacks are specified, this policy has the same behavior as `bearerTokenAuthenticationPolicy`. It will retrieve the token from the underlying token credential, and if it gets one, it will cache the token and set it to the outgoing request.
78
- `authorizeRequestOnChallenge`, which gets called only if we've found a challenge in the response. This callback has access to the original request and its response and is expected to handle the challenge. If this callback returns true, the request, usually updated after handling the challenge, will be sent again. If this call back returns false, no further actions will be taken.
9+
- Delay loading of NO_PROXY environment variable until when request pipeline is being created. This fixes [issue 14873](https://github.com/Azure/azure-sdk-for-js/issues/14873)
810

911
## 1.0.3 (2021-03-30)
1012

sdk/core/core-rest-pipeline/src/policies/proxyPolicy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const NO_PROXY = "NO_PROXY";
2525
*/
2626
export const proxyPolicyName = "proxyPolicy";
2727

28-
export const noProxyList: string[] = loadNoProxy();
28+
export const noProxyList: string[] = [];
29+
let noProxyListLoaded: boolean = false;
2930
const byPassedList: Map<string, boolean> = new Map();
3031

3132
let httpsProxyAgent: https.Agent | undefined;
@@ -86,6 +87,7 @@ function isBypassed(uri: string): boolean | undefined {
8687

8788
export function loadNoProxy(): string[] {
8889
const noProxy = getEnvironmentValue(NO_PROXY);
90+
noProxyListLoaded = true;
8991
if (noProxy) {
9092
return noProxy
9193
.split(",")
@@ -175,6 +177,9 @@ function setProxyAgentOnRequest(request: PipelineRequest): void {
175177
* @param proxySettings - ProxySettings to use on each request.
176178
*/
177179
export function proxyPolicy(proxySettings = getDefaultProxySettings()): PipelinePolicy {
180+
if (!noProxyListLoaded) {
181+
noProxyList.push(...loadNoProxy());
182+
}
178183
return {
179184
name: proxyPolicyName,
180185
async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {

0 commit comments

Comments
 (0)