@typespec/ts-http-runtime 1.0.0-alpha.20240314.2 → 1.0.0-alpha.20240322.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/policies/proxyPolicy.d.ts +2 -1
- package/dist/commonjs/policies/proxyPolicy.d.ts.map +1 -1
- package/dist/commonjs/policies/proxyPolicy.js +48 -28
- package/dist/commonjs/policies/proxyPolicy.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/esm/policies/proxyPolicy.d.ts +2 -1
- package/dist/esm/policies/proxyPolicy.d.ts.map +1 -1
- package/dist/esm/policies/proxyPolicy.js +48 -28
- package/dist/esm/policies/proxyPolicy.js.map +1 -1
- package/dist/react-native/policies/proxyPolicy.d.ts +2 -1
- package/dist/react-native/policies/proxyPolicy.d.ts.map +1 -1
- package/dist/react-native/policies/proxyPolicy.js +48 -28
- package/dist/react-native/policies/proxyPolicy.js.map +1 -1
- package/dist/ts-http-runtime.d.ts +2 -1
- package/package.json +2 -1
|
@@ -15,6 +15,7 @@ export declare function loadNoProxy(): string[];
|
|
|
15
15
|
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
16
16
|
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
17
17
|
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
18
|
+
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
18
19
|
*/
|
|
19
20
|
export declare function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined;
|
|
20
21
|
/**
|
|
@@ -24,7 +25,7 @@ export declare function getDefaultProxySettings(proxyUrl?: string): ProxySetting
|
|
|
24
25
|
* @param proxySettings - ProxySettings to use on each request.
|
|
25
26
|
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
26
27
|
*/
|
|
27
|
-
export declare function proxyPolicy(proxySettings?: ProxySettings
|
|
28
|
+
export declare function proxyPolicy(proxySettings?: ProxySettings, options?: {
|
|
28
29
|
/** a list of patterns to override those loaded from NO_PROXY environment variable. */
|
|
29
30
|
customNoProxyList?: string[];
|
|
30
31
|
}): PipelinePolicy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAO,CAAC;AAkE9C,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAWtC;AAED
|
|
1
|
+
{"version":3,"file":"proxyPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAO,CAAC;AAkE9C,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAWtC;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAgBpF;AAyED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,aAAa,CAAC,EAAE,aAAa,EAC7B,OAAO,CAAC,EAAE;IACR,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,GACA,cAAc,CAkChB"}
|
|
@@ -93,6 +93,7 @@ exports.loadNoProxy = loadNoProxy;
|
|
|
93
93
|
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
94
94
|
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
95
95
|
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
96
|
+
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
96
97
|
*/
|
|
97
98
|
function getDefaultProxySettings(proxyUrl) {
|
|
98
99
|
if (!proxyUrl) {
|
|
@@ -111,7 +112,32 @@ function getDefaultProxySettings(proxyUrl) {
|
|
|
111
112
|
};
|
|
112
113
|
}
|
|
113
114
|
exports.getDefaultProxySettings = getDefaultProxySettings;
|
|
114
|
-
|
|
115
|
+
/**
|
|
116
|
+
* This method attempts to parse a proxy URL from the environment
|
|
117
|
+
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
118
|
+
*/
|
|
119
|
+
function getDefaultProxySettingsInternal() {
|
|
120
|
+
const envProxy = loadEnvironmentProxyValue();
|
|
121
|
+
return envProxy ? new URL(envProxy) : undefined;
|
|
122
|
+
}
|
|
123
|
+
function getUrlFromProxySettings(settings) {
|
|
124
|
+
let parsedProxyUrl;
|
|
125
|
+
try {
|
|
126
|
+
parsedProxyUrl = new URL(settings.host);
|
|
127
|
+
}
|
|
128
|
+
catch (_error) {
|
|
129
|
+
throw new Error(`Expecting a valid host string in proxy settings, but found "${settings.host}".`);
|
|
130
|
+
}
|
|
131
|
+
parsedProxyUrl.port = String(settings.port);
|
|
132
|
+
if (settings.username) {
|
|
133
|
+
parsedProxyUrl.username = settings.username;
|
|
134
|
+
}
|
|
135
|
+
if (settings.password) {
|
|
136
|
+
parsedProxyUrl.password = settings.password;
|
|
137
|
+
}
|
|
138
|
+
return parsedProxyUrl;
|
|
139
|
+
}
|
|
140
|
+
function setProxyAgentOnRequest(request, cachedAgents, proxyUrl) {
|
|
115
141
|
// Custom Agent should take precedence so if one is present
|
|
116
142
|
// we should skip to avoid overwriting it.
|
|
117
143
|
if (request.agent) {
|
|
@@ -119,31 +145,21 @@ function setProxyAgentOnRequest(request, cachedAgents) {
|
|
|
119
145
|
}
|
|
120
146
|
const url = new URL(request.url);
|
|
121
147
|
const isInsecure = url.protocol !== "https:";
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
throw new Error(`Expecting a valid host string in proxy settings, but found "${proxySettings.host}".`);
|
|
130
|
-
}
|
|
131
|
-
if (request.tlsSettings) {
|
|
132
|
-
log_js_1.logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
133
|
-
}
|
|
134
|
-
const headers = request.headers.toJSON();
|
|
135
|
-
if (isInsecure) {
|
|
136
|
-
if (!cachedAgents.httpProxyAgent) {
|
|
137
|
-
cachedAgents.httpProxyAgent = new http_proxy_agent_1.HttpProxyAgent(parsedProxyUrl, { headers });
|
|
138
|
-
}
|
|
139
|
-
request.agent = cachedAgents.httpProxyAgent;
|
|
148
|
+
if (request.tlsSettings) {
|
|
149
|
+
log_js_1.logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
150
|
+
}
|
|
151
|
+
const headers = request.headers.toJSON();
|
|
152
|
+
if (isInsecure) {
|
|
153
|
+
if (!cachedAgents.httpProxyAgent) {
|
|
154
|
+
cachedAgents.httpProxyAgent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl, { headers });
|
|
140
155
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
156
|
+
request.agent = cachedAgents.httpProxyAgent;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (!cachedAgents.httpsProxyAgent) {
|
|
160
|
+
cachedAgents.httpsProxyAgent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl, { headers });
|
|
146
161
|
}
|
|
162
|
+
request.agent = cachedAgents.httpsProxyAgent;
|
|
147
163
|
}
|
|
148
164
|
}
|
|
149
165
|
/**
|
|
@@ -153,20 +169,24 @@ function setProxyAgentOnRequest(request, cachedAgents) {
|
|
|
153
169
|
* @param proxySettings - ProxySettings to use on each request.
|
|
154
170
|
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
155
171
|
*/
|
|
156
|
-
function proxyPolicy(proxySettings
|
|
172
|
+
function proxyPolicy(proxySettings, options) {
|
|
157
173
|
if (!noProxyListLoaded) {
|
|
158
174
|
exports.globalNoProxyList.push(...loadNoProxy());
|
|
159
175
|
}
|
|
176
|
+
const defaultProxy = proxySettings
|
|
177
|
+
? getUrlFromProxySettings(proxySettings)
|
|
178
|
+
: getDefaultProxySettingsInternal();
|
|
160
179
|
const cachedAgents = {};
|
|
161
180
|
return {
|
|
162
181
|
name: exports.proxyPolicyName,
|
|
163
182
|
async sendRequest(request, next) {
|
|
164
183
|
if (!request.proxySettings &&
|
|
184
|
+
defaultProxy &&
|
|
165
185
|
!isBypassed(request.url, options?.customNoProxyList ?? exports.globalNoProxyList, options?.customNoProxyList ? undefined : globalBypassedMap)) {
|
|
166
|
-
request
|
|
186
|
+
setProxyAgentOnRequest(request, cachedAgents, defaultProxy);
|
|
167
187
|
}
|
|
168
|
-
if (request.proxySettings) {
|
|
169
|
-
setProxyAgentOnRequest(request, cachedAgents);
|
|
188
|
+
else if (request.proxySettings) {
|
|
189
|
+
setProxyAgentOnRequest(request, cachedAgents, getUrlFromProxySettings(request.proxySettings));
|
|
170
190
|
}
|
|
171
191
|
return next(request);
|
|
172
192
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyPolicy.js","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAIlC,yDAAoD;AACpD,uDAAkD;AAQlD,sCAAmC;AAEnC,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B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YAAY,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAjCD,kCAiCC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as http from \"http\";\nimport type * as https from \"https\";\nimport { HttpsProxyAgent } from \"https-proxy-agent\";\nimport { HttpProxyAgent } from \"http-proxy-agent\";\nimport type {\n PipelineRequest,\n PipelineResponse,\n ProxySettings,\n SendRequest,\n} from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { logger } from \"../log.js\";\n\nconst HTTPS_PROXY = \"HTTPS_PROXY\";\nconst HTTP_PROXY = \"HTTP_PROXY\";\nconst ALL_PROXY = \"ALL_PROXY\";\nconst NO_PROXY = \"NO_PROXY\";\n\n/**\n * The programmatic identifier of the proxyPolicy.\n */\nexport const proxyPolicyName = \"proxyPolicy\";\n\n/**\n * Stores the patterns specified in NO_PROXY environment variable.\n * @internal\n */\nexport const globalNoProxyList: string[] = [];\nlet noProxyListLoaded: boolean = false;\n\n/** A cache of whether a host should bypass the proxy. */\nconst globalBypassedMap: Map<string, boolean> = new Map();\n\nfunction getEnvironmentValue(name: string): string | undefined {\n if (process.env[name]) {\n return process.env[name];\n } else if (process.env[name.toLowerCase()]) {\n return process.env[name.toLowerCase()];\n }\n return undefined;\n}\n\nfunction loadEnvironmentProxyValue(): string | undefined {\n if (!process) {\n return undefined;\n }\n\n const httpsProxy = getEnvironmentValue(HTTPS_PROXY);\n const allProxy = getEnvironmentValue(ALL_PROXY);\n const httpProxy = getEnvironmentValue(HTTP_PROXY);\n\n return httpsProxy || allProxy || httpProxy;\n}\n\n/**\n * Check whether the host of a given `uri` matches any pattern in the no proxy list.\n * If there's a match, any request sent to the same host shouldn't have the proxy settings set.\n * This implementation is a port of https://github.com/Azure/azure-sdk-for-net/blob/8cca811371159e527159c7eb65602477898683e2/sdk/core/Azure.Core/src/Pipeline/Internal/HttpEnvironmentProxy.cs#L210\n */\nfunction isBypassed(\n uri: string,\n noProxyList: string[],\n bypassedMap?: Map<string, boolean>,\n): boolean | undefined {\n if (noProxyList.length === 0) {\n return false;\n }\n const host = new URL(uri).hostname;\n if (bypassedMap?.has(host)) {\n return bypassedMap.get(host);\n }\n let isBypassedFlag = false;\n for (const pattern of noProxyList) {\n if (pattern[0] === \".\") {\n // This should match either domain it self or any subdomain or host\n // .foo.com will match foo.com it self or *.foo.com\n if (host.endsWith(pattern)) {\n isBypassedFlag = true;\n } else {\n if (host.length === pattern.length - 1 && host === pattern.slice(1)) {\n isBypassedFlag = true;\n }\n }\n } else {\n if (host === pattern) {\n isBypassedFlag = true;\n }\n }\n }\n bypassedMap?.set(host, isBypassedFlag);\n return isBypassedFlag;\n}\n\nexport function loadNoProxy(): string[] {\n const noProxy = getEnvironmentValue(NO_PROXY);\n noProxyListLoaded = true;\n if (noProxy) {\n return noProxy\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length);\n }\n\n return [];\n}\n\n/**\n * This method converts a proxy url into `ProxySettings` for use with ProxyPolicy.\n * If no argument is given, it attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n * @param proxyUrl - The url of the proxy to use. May contain authentication information.\n */\nexport function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined {\n if (!proxyUrl) {\n proxyUrl = loadEnvironmentProxyValue();\n if (!proxyUrl) {\n return undefined;\n }\n }\n\n const parsedUrl = new URL(proxyUrl);\n const schema = parsedUrl.protocol ? parsedUrl.protocol + \"//\" : \"\";\n return {\n host: schema + parsedUrl.hostname,\n port: Number.parseInt(parsedUrl.port || \"80\"),\n username: parsedUrl.username,\n password: parsedUrl.password,\n };\n}\n\nfunction setProxyAgentOnRequest(request: PipelineRequest, cachedAgents: CachedAgents): void {\n // Custom Agent should take precedence so if one is present\n // we should skip to avoid overwriting it.\n if (request.agent) {\n return;\n }\n\n const url = new URL(request.url);\n\n const isInsecure = url.protocol !== \"https:\";\n\n const proxySettings = request.proxySettings;\n if (proxySettings) {\n let parsedProxyUrl: URL;\n try {\n parsedProxyUrl = new URL(proxySettings.host);\n } catch (_error) {\n throw new Error(\n `Expecting a valid host string in proxy settings, but found \"${proxySettings.host}\".`,\n );\n }\n\n if (request.tlsSettings) {\n logger.warning(\n \"TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.\",\n );\n }\n\n const headers = request.headers.toJSON();\n\n if (isInsecure) {\n if (!cachedAgents.httpProxyAgent) {\n cachedAgents.httpProxyAgent = new HttpProxyAgent(parsedProxyUrl, { headers });\n }\n request.agent = cachedAgents.httpProxyAgent;\n } else {\n if (!cachedAgents.httpsProxyAgent) {\n cachedAgents.httpsProxyAgent = new HttpsProxyAgent(parsedProxyUrl, { headers });\n }\n request.agent = cachedAgents.httpsProxyAgent;\n }\n }\n}\n\ninterface CachedAgents {\n httpsProxyAgent?: https.Agent;\n httpProxyAgent?: http.Agent;\n}\n\n/**\n * A policy that allows one to apply proxy settings to all requests.\n * If not passed static settings, they will be retrieved from the HTTPS_PROXY\n * or HTTP_PROXY environment variables.\n * @param proxySettings - ProxySettings to use on each request.\n * @param options - additional settings, for example, custom NO_PROXY patterns\n */\nexport function proxyPolicy(\n proxySettings = getDefaultProxySettings(),\n options?: {\n /** a list of patterns to override those loaded from NO_PROXY environment variable. */\n customNoProxyList?: string[];\n },\n): PipelinePolicy {\n if (!noProxyListLoaded) {\n globalNoProxyList.push(...loadNoProxy());\n }\n\n const cachedAgents: CachedAgents = {};\n\n return {\n name: proxyPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (\n !request.proxySettings &&\n !isBypassed(\n request.url,\n options?.customNoProxyList ?? globalNoProxyList,\n options?.customNoProxyList ? undefined : globalBypassedMap,\n )\n ) {\n request.proxySettings = proxySettings;\n }\n\n if (request.proxySettings) {\n setProxyAgentOnRequest(request, cachedAgents);\n }\n return next(request);\n },\n };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e,GAAG,IAAI,mCAAe,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC,eAAe,CAAC;IAC/C,CAAC;AACH,CAAC;AAOD;;;;;;GAMG;AACH,SAAgB,WAAW,CACzB,aAA6B,EAC7B,OAGC;IAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,yBAAiB,CAAC,IAAI,CAAC,GAAG,WAAW,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,YAAY,GAAG,aAAa;QAChC,CAAC,CAAC,uBAAuB,CAAC,aAAa,CAAC;QACxC,CAAC,CAAC,+BAA+B,EAAE,CAAC;IAEtC,MAAM,YAAY,GAAiB,EAAE,CAAC;IAEtC,OAAO;QACL,IAAI,EAAE,uBAAe;QACrB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IACE,CAAC,OAAO,CAAC,aAAa;gBACtB,YAAY;gBACZ,CAAC,UAAU,CACT,OAAO,CAAC,GAAG,EACX,OAAO,EAAE,iBAAiB,IAAI,yBAAiB,EAC/C,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAC3D,EACD,CAAC;gBACD,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACjC,sBAAsB,CACpB,OAAO,EACP,YAAY,EACZ,uBAAuB,CAAC,OAAO,CAAC,aAAa,CAAC,CAC/C,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAxCD,kCAwCC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as http from \"http\";\nimport type * as https from \"https\";\nimport { HttpsProxyAgent } from \"https-proxy-agent\";\nimport { HttpProxyAgent } from \"http-proxy-agent\";\nimport type {\n PipelineRequest,\n PipelineResponse,\n ProxySettings,\n SendRequest,\n} from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { logger } from \"../log.js\";\n\nconst HTTPS_PROXY = \"HTTPS_PROXY\";\nconst HTTP_PROXY = \"HTTP_PROXY\";\nconst ALL_PROXY = \"ALL_PROXY\";\nconst NO_PROXY = \"NO_PROXY\";\n\n/**\n * The programmatic identifier of the proxyPolicy.\n */\nexport const proxyPolicyName = \"proxyPolicy\";\n\n/**\n * Stores the patterns specified in NO_PROXY environment variable.\n * @internal\n */\nexport const globalNoProxyList: string[] = [];\nlet noProxyListLoaded: boolean = false;\n\n/** A cache of whether a host should bypass the proxy. */\nconst globalBypassedMap: Map<string, boolean> = new Map();\n\nfunction getEnvironmentValue(name: string): string | undefined {\n if (process.env[name]) {\n return process.env[name];\n } else if (process.env[name.toLowerCase()]) {\n return process.env[name.toLowerCase()];\n }\n return undefined;\n}\n\nfunction loadEnvironmentProxyValue(): string | undefined {\n if (!process) {\n return undefined;\n }\n\n const httpsProxy = getEnvironmentValue(HTTPS_PROXY);\n const allProxy = getEnvironmentValue(ALL_PROXY);\n const httpProxy = getEnvironmentValue(HTTP_PROXY);\n\n return httpsProxy || allProxy || httpProxy;\n}\n\n/**\n * Check whether the host of a given `uri` matches any pattern in the no proxy list.\n * If there's a match, any request sent to the same host shouldn't have the proxy settings set.\n * This implementation is a port of https://github.com/Azure/azure-sdk-for-net/blob/8cca811371159e527159c7eb65602477898683e2/sdk/core/Azure.Core/src/Pipeline/Internal/HttpEnvironmentProxy.cs#L210\n */\nfunction isBypassed(\n uri: string,\n noProxyList: string[],\n bypassedMap?: Map<string, boolean>,\n): boolean | undefined {\n if (noProxyList.length === 0) {\n return false;\n }\n const host = new URL(uri).hostname;\n if (bypassedMap?.has(host)) {\n return bypassedMap.get(host);\n }\n let isBypassedFlag = false;\n for (const pattern of noProxyList) {\n if (pattern[0] === \".\") {\n // This should match either domain it self or any subdomain or host\n // .foo.com will match foo.com it self or *.foo.com\n if (host.endsWith(pattern)) {\n isBypassedFlag = true;\n } else {\n if (host.length === pattern.length - 1 && host === pattern.slice(1)) {\n isBypassedFlag = true;\n }\n }\n } else {\n if (host === pattern) {\n isBypassedFlag = true;\n }\n }\n }\n bypassedMap?.set(host, isBypassedFlag);\n return isBypassedFlag;\n}\n\nexport function loadNoProxy(): string[] {\n const noProxy = getEnvironmentValue(NO_PROXY);\n noProxyListLoaded = true;\n if (noProxy) {\n return noProxy\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length);\n }\n\n return [];\n}\n\n/**\n * This method converts a proxy url into `ProxySettings` for use with ProxyPolicy.\n * If no argument is given, it attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n * @param proxyUrl - The url of the proxy to use. May contain authentication information.\n * @deprecated - Internally this method is no longer necessary when setting proxy information.\n */\nexport function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined {\n if (!proxyUrl) {\n proxyUrl = loadEnvironmentProxyValue();\n if (!proxyUrl) {\n return undefined;\n }\n }\n\n const parsedUrl = new URL(proxyUrl);\n const schema = parsedUrl.protocol ? parsedUrl.protocol + \"//\" : \"\";\n return {\n host: schema + parsedUrl.hostname,\n port: Number.parseInt(parsedUrl.port || \"80\"),\n username: parsedUrl.username,\n password: parsedUrl.password,\n };\n}\n\n/**\n * This method attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n */\nfunction getDefaultProxySettingsInternal(): URL | undefined {\n const envProxy = loadEnvironmentProxyValue();\n return envProxy ? new URL(envProxy) : undefined;\n}\n\nfunction getUrlFromProxySettings(settings: ProxySettings): URL {\n let parsedProxyUrl: URL;\n try {\n parsedProxyUrl = new URL(settings.host);\n } catch (_error) {\n throw new Error(\n `Expecting a valid host string in proxy settings, but found \"${settings.host}\".`,\n );\n }\n\n parsedProxyUrl.port = String(settings.port);\n if (settings.username) {\n parsedProxyUrl.username = settings.username;\n }\n if (settings.password) {\n parsedProxyUrl.password = settings.password;\n }\n\n return parsedProxyUrl;\n}\n\nfunction setProxyAgentOnRequest(\n request: PipelineRequest,\n cachedAgents: CachedAgents,\n proxyUrl: URL,\n): void {\n // Custom Agent should take precedence so if one is present\n // we should skip to avoid overwriting it.\n if (request.agent) {\n return;\n }\n\n const url = new URL(request.url);\n\n const isInsecure = url.protocol !== \"https:\";\n\n if (request.tlsSettings) {\n logger.warning(\n \"TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.\",\n );\n }\n\n const headers = request.headers.toJSON();\n\n if (isInsecure) {\n if (!cachedAgents.httpProxyAgent) {\n cachedAgents.httpProxyAgent = new HttpProxyAgent(proxyUrl, { headers });\n }\n request.agent = cachedAgents.httpProxyAgent;\n } else {\n if (!cachedAgents.httpsProxyAgent) {\n cachedAgents.httpsProxyAgent = new HttpsProxyAgent(proxyUrl, { headers });\n }\n request.agent = cachedAgents.httpsProxyAgent;\n }\n}\n\ninterface CachedAgents {\n httpsProxyAgent?: https.Agent;\n httpProxyAgent?: http.Agent;\n}\n\n/**\n * A policy that allows one to apply proxy settings to all requests.\n * If not passed static settings, they will be retrieved from the HTTPS_PROXY\n * or HTTP_PROXY environment variables.\n * @param proxySettings - ProxySettings to use on each request.\n * @param options - additional settings, for example, custom NO_PROXY patterns\n */\nexport function proxyPolicy(\n proxySettings?: ProxySettings,\n options?: {\n /** a list of patterns to override those loaded from NO_PROXY environment variable. */\n customNoProxyList?: string[];\n },\n): PipelinePolicy {\n if (!noProxyListLoaded) {\n globalNoProxyList.push(...loadNoProxy());\n }\n\n const defaultProxy = proxySettings\n ? getUrlFromProxySettings(proxySettings)\n : getDefaultProxySettingsInternal();\n\n const cachedAgents: CachedAgents = {};\n\n return {\n name: proxyPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (\n !request.proxySettings &&\n defaultProxy &&\n !isBypassed(\n request.url,\n options?.customNoProxyList ?? globalNoProxyList,\n options?.customNoProxyList ? undefined : globalBypassedMap,\n )\n ) {\n setProxyAgentOnRequest(request, cachedAgents, defaultProxy);\n } else if (request.proxySettings) {\n setProxyAgentOnRequest(\n request,\n cachedAgents,\n getUrlFromProxySettings(request.proxySettings),\n );\n }\n return next(request);\n },\n };\n}\n"]}
|
|
@@ -15,6 +15,7 @@ export declare function loadNoProxy(): string[];
|
|
|
15
15
|
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
16
16
|
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
17
17
|
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
18
|
+
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
18
19
|
*/
|
|
19
20
|
export declare function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined;
|
|
20
21
|
/**
|
|
@@ -24,7 +25,7 @@ export declare function getDefaultProxySettings(proxyUrl?: string): ProxySetting
|
|
|
24
25
|
* @param proxySettings - ProxySettings to use on each request.
|
|
25
26
|
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
26
27
|
*/
|
|
27
|
-
export declare function proxyPolicy(proxySettings?: ProxySettings
|
|
28
|
+
export declare function proxyPolicy(proxySettings?: ProxySettings, options?: {
|
|
28
29
|
/** a list of patterns to override those loaded from NO_PROXY environment variable. */
|
|
29
30
|
customNoProxyList?: string[];
|
|
30
31
|
}): PipelinePolicy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAO,CAAC;AAkE9C,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAWtC;AAED
|
|
1
|
+
{"version":3,"file":"proxyPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAO,CAAC;AAkE9C,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAWtC;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAgBpF;AAyED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,aAAa,CAAC,EAAE,aAAa,EAC7B,OAAO,CAAC,EAAE;IACR,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,GACA,cAAc,CAkChB"}
|
|
@@ -89,6 +89,7 @@ export function loadNoProxy() {
|
|
|
89
89
|
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
90
90
|
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
91
91
|
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
92
|
+
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
92
93
|
*/
|
|
93
94
|
export function getDefaultProxySettings(proxyUrl) {
|
|
94
95
|
if (!proxyUrl) {
|
|
@@ -106,7 +107,32 @@ export function getDefaultProxySettings(proxyUrl) {
|
|
|
106
107
|
password: parsedUrl.password,
|
|
107
108
|
};
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
+
/**
|
|
111
|
+
* This method attempts to parse a proxy URL from the environment
|
|
112
|
+
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
113
|
+
*/
|
|
114
|
+
function getDefaultProxySettingsInternal() {
|
|
115
|
+
const envProxy = loadEnvironmentProxyValue();
|
|
116
|
+
return envProxy ? new URL(envProxy) : undefined;
|
|
117
|
+
}
|
|
118
|
+
function getUrlFromProxySettings(settings) {
|
|
119
|
+
let parsedProxyUrl;
|
|
120
|
+
try {
|
|
121
|
+
parsedProxyUrl = new URL(settings.host);
|
|
122
|
+
}
|
|
123
|
+
catch (_error) {
|
|
124
|
+
throw new Error(`Expecting a valid host string in proxy settings, but found "${settings.host}".`);
|
|
125
|
+
}
|
|
126
|
+
parsedProxyUrl.port = String(settings.port);
|
|
127
|
+
if (settings.username) {
|
|
128
|
+
parsedProxyUrl.username = settings.username;
|
|
129
|
+
}
|
|
130
|
+
if (settings.password) {
|
|
131
|
+
parsedProxyUrl.password = settings.password;
|
|
132
|
+
}
|
|
133
|
+
return parsedProxyUrl;
|
|
134
|
+
}
|
|
135
|
+
function setProxyAgentOnRequest(request, cachedAgents, proxyUrl) {
|
|
110
136
|
// Custom Agent should take precedence so if one is present
|
|
111
137
|
// we should skip to avoid overwriting it.
|
|
112
138
|
if (request.agent) {
|
|
@@ -114,31 +140,21 @@ function setProxyAgentOnRequest(request, cachedAgents) {
|
|
|
114
140
|
}
|
|
115
141
|
const url = new URL(request.url);
|
|
116
142
|
const isInsecure = url.protocol !== "https:";
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
throw new Error(`Expecting a valid host string in proxy settings, but found "${proxySettings.host}".`);
|
|
125
|
-
}
|
|
126
|
-
if (request.tlsSettings) {
|
|
127
|
-
logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
128
|
-
}
|
|
129
|
-
const headers = request.headers.toJSON();
|
|
130
|
-
if (isInsecure) {
|
|
131
|
-
if (!cachedAgents.httpProxyAgent) {
|
|
132
|
-
cachedAgents.httpProxyAgent = new HttpProxyAgent(parsedProxyUrl, { headers });
|
|
133
|
-
}
|
|
134
|
-
request.agent = cachedAgents.httpProxyAgent;
|
|
143
|
+
if (request.tlsSettings) {
|
|
144
|
+
logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
145
|
+
}
|
|
146
|
+
const headers = request.headers.toJSON();
|
|
147
|
+
if (isInsecure) {
|
|
148
|
+
if (!cachedAgents.httpProxyAgent) {
|
|
149
|
+
cachedAgents.httpProxyAgent = new HttpProxyAgent(proxyUrl, { headers });
|
|
135
150
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
request.agent = cachedAgents.httpProxyAgent;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (!cachedAgents.httpsProxyAgent) {
|
|
155
|
+
cachedAgents.httpsProxyAgent = new HttpsProxyAgent(proxyUrl, { headers });
|
|
141
156
|
}
|
|
157
|
+
request.agent = cachedAgents.httpsProxyAgent;
|
|
142
158
|
}
|
|
143
159
|
}
|
|
144
160
|
/**
|
|
@@ -148,20 +164,24 @@ function setProxyAgentOnRequest(request, cachedAgents) {
|
|
|
148
164
|
* @param proxySettings - ProxySettings to use on each request.
|
|
149
165
|
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
150
166
|
*/
|
|
151
|
-
export function proxyPolicy(proxySettings
|
|
167
|
+
export function proxyPolicy(proxySettings, options) {
|
|
152
168
|
if (!noProxyListLoaded) {
|
|
153
169
|
globalNoProxyList.push(...loadNoProxy());
|
|
154
170
|
}
|
|
171
|
+
const defaultProxy = proxySettings
|
|
172
|
+
? getUrlFromProxySettings(proxySettings)
|
|
173
|
+
: getDefaultProxySettingsInternal();
|
|
155
174
|
const cachedAgents = {};
|
|
156
175
|
return {
|
|
157
176
|
name: proxyPolicyName,
|
|
158
177
|
async sendRequest(request, next) {
|
|
159
178
|
if (!request.proxySettings &&
|
|
179
|
+
defaultProxy &&
|
|
160
180
|
!isBypassed(request.url, options?.customNoProxyList ?? globalNoProxyList, options?.customNoProxyList ? undefined : globalBypassedMap)) {
|
|
161
|
-
request
|
|
181
|
+
setProxyAgentOnRequest(request, cachedAgents, defaultProxy);
|
|
162
182
|
}
|
|
163
|
-
if (request.proxySettings) {
|
|
164
|
-
setProxyAgentOnRequest(request, cachedAgents);
|
|
183
|
+
else if (request.proxySettings) {
|
|
184
|
+
setProxyAgentOnRequest(request, cachedAgents, getUrlFromProxySettings(request.proxySettings));
|
|
165
185
|
}
|
|
166
186
|
return next(request);
|
|
167
187
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyPolicy.js","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQlD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAa,EAAE,CAAC;AAC9C,IAAI,iBAAiB,GAAY,KAAK,CAAC;AAEvC,yDAAyD;AACzD,MAAM,iBAAiB,GAAyB,IAAI,GAAG,EAAE,CAAC;AAE1D,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;SAAM,IAAI,OAA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e,GAAG,IAAI,eAAe,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YAClF,CAAC;YACD,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC,eAAe,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAOD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CACzB,aAAa,GAAG,uBAAuB,EAAE,EACzC,OAGC;IAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,iBAAiB,CAAC,IAAI,CAAC,GAAG,WAAW,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,YAAY,GAAiB,EAAE,CAAC;IAEtC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IACE,CAAC,OAAO,CAAC,aAAa;gBACtB,CAAC,UAAU,CACT,OAAO,CAAC,GAAG,EACX,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAC/C,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAC3D,EACD,CAAC;gBACD,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;YACxC,CAAC;YAED,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBAC1B,sBAAsB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as http from \"http\";\nimport type * as https from \"https\";\nimport { HttpsProxyAgent } from \"https-proxy-agent\";\nimport { HttpProxyAgent } from \"http-proxy-agent\";\nimport type {\n PipelineRequest,\n PipelineResponse,\n ProxySettings,\n SendRequest,\n} from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { logger } from \"../log.js\";\n\nconst HTTPS_PROXY = \"HTTPS_PROXY\";\nconst HTTP_PROXY = \"HTTP_PROXY\";\nconst ALL_PROXY = \"ALL_PROXY\";\nconst NO_PROXY = \"NO_PROXY\";\n\n/**\n * The programmatic identifier of the proxyPolicy.\n */\nexport const proxyPolicyName = \"proxyPolicy\";\n\n/**\n * Stores the patterns specified in NO_PROXY environment variable.\n * @internal\n */\nexport const globalNoProxyList: string[] = [];\nlet noProxyListLoaded: boolean = false;\n\n/** A cache of whether a host should bypass the proxy. */\nconst globalBypassedMap: Map<string, boolean> = new Map();\n\nfunction getEnvironmentValue(name: string): string | undefined {\n if (process.env[name]) {\n return process.env[name];\n } else if (process.env[name.toLowerCase()]) {\n return process.env[name.toLowerCase()];\n }\n return undefined;\n}\n\nfunction loadEnvironmentProxyValue(): string | undefined {\n if (!process) {\n return undefined;\n }\n\n const httpsProxy = getEnvironmentValue(HTTPS_PROXY);\n const allProxy = getEnvironmentValue(ALL_PROXY);\n const httpProxy = getEnvironmentValue(HTTP_PROXY);\n\n return httpsProxy || allProxy || httpProxy;\n}\n\n/**\n * Check whether the host of a given `uri` matches any pattern in the no proxy list.\n * If there's a match, any request sent to the same host shouldn't have the proxy settings set.\n * This implementation is a port of https://github.com/Azure/azure-sdk-for-net/blob/8cca811371159e527159c7eb65602477898683e2/sdk/core/Azure.Core/src/Pipeline/Internal/HttpEnvironmentProxy.cs#L210\n */\nfunction isBypassed(\n uri: string,\n noProxyList: string[],\n bypassedMap?: Map<string, boolean>,\n): boolean | undefined {\n if (noProxyList.length === 0) {\n return false;\n }\n const host = new URL(uri).hostname;\n if (bypassedMap?.has(host)) {\n return bypassedMap.get(host);\n }\n let isBypassedFlag = false;\n for (const pattern of noProxyList) {\n if (pattern[0] === \".\") {\n // This should match either domain it self or any subdomain or host\n // .foo.com will match foo.com it self or *.foo.com\n if (host.endsWith(pattern)) {\n isBypassedFlag = true;\n } else {\n if (host.length === pattern.length - 1 && host === pattern.slice(1)) {\n isBypassedFlag = true;\n }\n }\n } else {\n if (host === pattern) {\n isBypassedFlag = true;\n }\n }\n }\n bypassedMap?.set(host, isBypassedFlag);\n return isBypassedFlag;\n}\n\nexport function loadNoProxy(): string[] {\n const noProxy = getEnvironmentValue(NO_PROXY);\n noProxyListLoaded = true;\n if (noProxy) {\n return noProxy\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length);\n }\n\n return [];\n}\n\n/**\n * This method converts a proxy url into `ProxySettings` for use with ProxyPolicy.\n * If no argument is given, it attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n * @param proxyUrl - The url of the proxy to use. May contain authentication information.\n */\nexport function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined {\n if (!proxyUrl) {\n proxyUrl = loadEnvironmentProxyValue();\n if (!proxyUrl) {\n return undefined;\n }\n }\n\n const parsedUrl = new URL(proxyUrl);\n const schema = parsedUrl.protocol ? parsedUrl.protocol + \"//\" : \"\";\n return {\n host: schema + parsedUrl.hostname,\n port: Number.parseInt(parsedUrl.port || \"80\"),\n username: parsedUrl.username,\n password: parsedUrl.password,\n };\n}\n\nfunction setProxyAgentOnRequest(request: PipelineRequest, cachedAgents: CachedAgents): void {\n // Custom Agent should take precedence so if one is present\n // we should skip to avoid overwriting it.\n if (request.agent) {\n return;\n }\n\n const url = new URL(request.url);\n\n const isInsecure = url.protocol !== \"https:\";\n\n const proxySettings = request.proxySettings;\n if (proxySettings) {\n let parsedProxyUrl: URL;\n try {\n parsedProxyUrl = new URL(proxySettings.host);\n } catch (_error) {\n throw new Error(\n `Expecting a valid host string in proxy settings, but found \"${proxySettings.host}\".`,\n );\n }\n\n if (request.tlsSettings) {\n logger.warning(\n \"TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.\",\n );\n }\n\n const headers = request.headers.toJSON();\n\n if (isInsecure) {\n if (!cachedAgents.httpProxyAgent) {\n cachedAgents.httpProxyAgent = new HttpProxyAgent(parsedProxyUrl, { headers });\n }\n request.agent = cachedAgents.httpProxyAgent;\n } else {\n if (!cachedAgents.httpsProxyAgent) {\n cachedAgents.httpsProxyAgent = new HttpsProxyAgent(parsedProxyUrl, { headers });\n }\n request.agent = cachedAgents.httpsProxyAgent;\n }\n }\n}\n\ninterface CachedAgents {\n httpsProxyAgent?: https.Agent;\n httpProxyAgent?: http.Agent;\n}\n\n/**\n * A policy that allows one to apply proxy settings to all requests.\n * If not passed static settings, they will be retrieved from the HTTPS_PROXY\n * or HTTP_PROXY environment variables.\n * @param proxySettings - ProxySettings to use on each request.\n * @param options - additional settings, for example, custom NO_PROXY patterns\n */\nexport function proxyPolicy(\n proxySettings = getDefaultProxySettings(),\n options?: {\n /** a list of patterns to override those loaded from NO_PROXY environment variable. */\n customNoProxyList?: string[];\n },\n): PipelinePolicy {\n if (!noProxyListLoaded) {\n globalNoProxyList.push(...loadNoProxy());\n }\n\n const cachedAgents: CachedAgents = {};\n\n return {\n name: proxyPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (\n !request.proxySettings &&\n !isBypassed(\n request.url,\n options?.customNoProxyList ?? globalNoProxyList,\n options?.customNoProxyList ? undefined : globalBypassedMap,\n )\n ) {\n request.proxySettings = proxySettings;\n }\n\n if (request.proxySettings) {\n setProxyAgentOnRequest(request, cachedAgents);\n }\n return next(request);\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"proxyPolicy.js","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQlD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,QAAQ,GAA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W,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,YAAY,GAAG,aAAa;QAChC,CAAC,CAAC,uBAAuB,CAAC,aAAa,CAAC;QACxC,CAAC,CAAC,+BAA+B,EAAE,CAAC;IAEtC,MAAM,YAAY,GAAiB,EAAE,CAAC;IAEtC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IACE,CAAC,OAAO,CAAC,aAAa;gBACtB,YAAY;gBACZ,CAAC,UAAU,CACT,OAAO,CAAC,GAAG,EACX,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAC/C,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAC3D,EACD,CAAC;gBACD,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACjC,sBAAsB,CACpB,OAAO,EACP,YAAY,EACZ,uBAAuB,CAAC,OAAO,CAAC,aAAa,CAAC,CAC/C,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as http from \"http\";\nimport type * as https from \"https\";\nimport { HttpsProxyAgent } from \"https-proxy-agent\";\nimport { HttpProxyAgent } from \"http-proxy-agent\";\nimport type {\n PipelineRequest,\n PipelineResponse,\n ProxySettings,\n SendRequest,\n} from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { logger } from \"../log.js\";\n\nconst HTTPS_PROXY = \"HTTPS_PROXY\";\nconst HTTP_PROXY = \"HTTP_PROXY\";\nconst ALL_PROXY = \"ALL_PROXY\";\nconst NO_PROXY = \"NO_PROXY\";\n\n/**\n * The programmatic identifier of the proxyPolicy.\n */\nexport const proxyPolicyName = \"proxyPolicy\";\n\n/**\n * Stores the patterns specified in NO_PROXY environment variable.\n * @internal\n */\nexport const globalNoProxyList: string[] = [];\nlet noProxyListLoaded: boolean = false;\n\n/** A cache of whether a host should bypass the proxy. */\nconst globalBypassedMap: Map<string, boolean> = new Map();\n\nfunction getEnvironmentValue(name: string): string | undefined {\n if (process.env[name]) {\n return process.env[name];\n } else if (process.env[name.toLowerCase()]) {\n return process.env[name.toLowerCase()];\n }\n return undefined;\n}\n\nfunction loadEnvironmentProxyValue(): string | undefined {\n if (!process) {\n return undefined;\n }\n\n const httpsProxy = getEnvironmentValue(HTTPS_PROXY);\n const allProxy = getEnvironmentValue(ALL_PROXY);\n const httpProxy = getEnvironmentValue(HTTP_PROXY);\n\n return httpsProxy || allProxy || httpProxy;\n}\n\n/**\n * Check whether the host of a given `uri` matches any pattern in the no proxy list.\n * If there's a match, any request sent to the same host shouldn't have the proxy settings set.\n * This implementation is a port of https://github.com/Azure/azure-sdk-for-net/blob/8cca811371159e527159c7eb65602477898683e2/sdk/core/Azure.Core/src/Pipeline/Internal/HttpEnvironmentProxy.cs#L210\n */\nfunction isBypassed(\n uri: string,\n noProxyList: string[],\n bypassedMap?: Map<string, boolean>,\n): boolean | undefined {\n if (noProxyList.length === 0) {\n return false;\n }\n const host = new URL(uri).hostname;\n if (bypassedMap?.has(host)) {\n return bypassedMap.get(host);\n }\n let isBypassedFlag = false;\n for (const pattern of noProxyList) {\n if (pattern[0] === \".\") {\n // This should match either domain it self or any subdomain or host\n // .foo.com will match foo.com it self or *.foo.com\n if (host.endsWith(pattern)) {\n isBypassedFlag = true;\n } else {\n if (host.length === pattern.length - 1 && host === pattern.slice(1)) {\n isBypassedFlag = true;\n }\n }\n } else {\n if (host === pattern) {\n isBypassedFlag = true;\n }\n }\n }\n bypassedMap?.set(host, isBypassedFlag);\n return isBypassedFlag;\n}\n\nexport function loadNoProxy(): string[] {\n const noProxy = getEnvironmentValue(NO_PROXY);\n noProxyListLoaded = true;\n if (noProxy) {\n return noProxy\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length);\n }\n\n return [];\n}\n\n/**\n * This method converts a proxy url into `ProxySettings` for use with ProxyPolicy.\n * If no argument is given, it attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n * @param proxyUrl - The url of the proxy to use. May contain authentication information.\n * @deprecated - Internally this method is no longer necessary when setting proxy information.\n */\nexport function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined {\n if (!proxyUrl) {\n proxyUrl = loadEnvironmentProxyValue();\n if (!proxyUrl) {\n return undefined;\n }\n }\n\n const parsedUrl = new URL(proxyUrl);\n const schema = parsedUrl.protocol ? parsedUrl.protocol + \"//\" : \"\";\n return {\n host: schema + parsedUrl.hostname,\n port: Number.parseInt(parsedUrl.port || \"80\"),\n username: parsedUrl.username,\n password: parsedUrl.password,\n };\n}\n\n/**\n * This method attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n */\nfunction getDefaultProxySettingsInternal(): URL | undefined {\n const envProxy = loadEnvironmentProxyValue();\n return envProxy ? new URL(envProxy) : undefined;\n}\n\nfunction getUrlFromProxySettings(settings: ProxySettings): URL {\n let parsedProxyUrl: URL;\n try {\n parsedProxyUrl = new URL(settings.host);\n } catch (_error) {\n throw new Error(\n `Expecting a valid host string in proxy settings, but found \"${settings.host}\".`,\n );\n }\n\n parsedProxyUrl.port = String(settings.port);\n if (settings.username) {\n parsedProxyUrl.username = settings.username;\n }\n if (settings.password) {\n parsedProxyUrl.password = settings.password;\n }\n\n return parsedProxyUrl;\n}\n\nfunction setProxyAgentOnRequest(\n request: PipelineRequest,\n cachedAgents: CachedAgents,\n proxyUrl: URL,\n): void {\n // Custom Agent should take precedence so if one is present\n // we should skip to avoid overwriting it.\n if (request.agent) {\n return;\n }\n\n const url = new URL(request.url);\n\n const isInsecure = url.protocol !== \"https:\";\n\n if (request.tlsSettings) {\n logger.warning(\n \"TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.\",\n );\n }\n\n const headers = request.headers.toJSON();\n\n if (isInsecure) {\n if (!cachedAgents.httpProxyAgent) {\n cachedAgents.httpProxyAgent = new HttpProxyAgent(proxyUrl, { headers });\n }\n request.agent = cachedAgents.httpProxyAgent;\n } else {\n if (!cachedAgents.httpsProxyAgent) {\n cachedAgents.httpsProxyAgent = new HttpsProxyAgent(proxyUrl, { headers });\n }\n request.agent = cachedAgents.httpsProxyAgent;\n }\n}\n\ninterface CachedAgents {\n httpsProxyAgent?: https.Agent;\n httpProxyAgent?: http.Agent;\n}\n\n/**\n * A policy that allows one to apply proxy settings to all requests.\n * If not passed static settings, they will be retrieved from the HTTPS_PROXY\n * or HTTP_PROXY environment variables.\n * @param proxySettings - ProxySettings to use on each request.\n * @param options - additional settings, for example, custom NO_PROXY patterns\n */\nexport function proxyPolicy(\n proxySettings?: ProxySettings,\n options?: {\n /** a list of patterns to override those loaded from NO_PROXY environment variable. */\n customNoProxyList?: string[];\n },\n): PipelinePolicy {\n if (!noProxyListLoaded) {\n globalNoProxyList.push(...loadNoProxy());\n }\n\n const defaultProxy = proxySettings\n ? getUrlFromProxySettings(proxySettings)\n : getDefaultProxySettingsInternal();\n\n const cachedAgents: CachedAgents = {};\n\n return {\n name: proxyPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (\n !request.proxySettings &&\n defaultProxy &&\n !isBypassed(\n request.url,\n options?.customNoProxyList ?? globalNoProxyList,\n options?.customNoProxyList ? undefined : globalBypassedMap,\n )\n ) {\n setProxyAgentOnRequest(request, cachedAgents, defaultProxy);\n } else if (request.proxySettings) {\n setProxyAgentOnRequest(\n request,\n cachedAgents,\n getUrlFromProxySettings(request.proxySettings),\n );\n }\n return next(request);\n },\n };\n}\n"]}
|
|
@@ -15,6 +15,7 @@ export declare function loadNoProxy(): string[];
|
|
|
15
15
|
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
16
16
|
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
17
17
|
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
18
|
+
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
18
19
|
*/
|
|
19
20
|
export declare function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined;
|
|
20
21
|
/**
|
|
@@ -24,7 +25,7 @@ export declare function getDefaultProxySettings(proxyUrl?: string): ProxySetting
|
|
|
24
25
|
* @param proxySettings - ProxySettings to use on each request.
|
|
25
26
|
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
26
27
|
*/
|
|
27
|
-
export declare function proxyPolicy(proxySettings?: ProxySettings
|
|
28
|
+
export declare function proxyPolicy(proxySettings?: ProxySettings, options?: {
|
|
28
29
|
/** a list of patterns to override those loaded from NO_PROXY environment variable. */
|
|
29
30
|
customNoProxyList?: string[];
|
|
30
31
|
}): PipelinePolicy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAO,CAAC;AAkE9C,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAWtC;AAED
|
|
1
|
+
{"version":3,"file":"proxyPolicy.d.ts","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGV,aAAa,EAEd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQrD;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAO,CAAC;AAkE9C,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAWtC;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAgBpF;AAyED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,aAAa,CAAC,EAAE,aAAa,EAC7B,OAAO,CAAC,EAAE;IACR,sFAAsF;IACtF,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC9B,GACA,cAAc,CAkChB"}
|
|
@@ -89,6 +89,7 @@ export function loadNoProxy() {
|
|
|
89
89
|
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
90
90
|
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
91
91
|
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
92
|
+
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
92
93
|
*/
|
|
93
94
|
export function getDefaultProxySettings(proxyUrl) {
|
|
94
95
|
if (!proxyUrl) {
|
|
@@ -106,7 +107,32 @@ export function getDefaultProxySettings(proxyUrl) {
|
|
|
106
107
|
password: parsedUrl.password,
|
|
107
108
|
};
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
+
/**
|
|
111
|
+
* This method attempts to parse a proxy URL from the environment
|
|
112
|
+
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
113
|
+
*/
|
|
114
|
+
function getDefaultProxySettingsInternal() {
|
|
115
|
+
const envProxy = loadEnvironmentProxyValue();
|
|
116
|
+
return envProxy ? new URL(envProxy) : undefined;
|
|
117
|
+
}
|
|
118
|
+
function getUrlFromProxySettings(settings) {
|
|
119
|
+
let parsedProxyUrl;
|
|
120
|
+
try {
|
|
121
|
+
parsedProxyUrl = new URL(settings.host);
|
|
122
|
+
}
|
|
123
|
+
catch (_error) {
|
|
124
|
+
throw new Error(`Expecting a valid host string in proxy settings, but found "${settings.host}".`);
|
|
125
|
+
}
|
|
126
|
+
parsedProxyUrl.port = String(settings.port);
|
|
127
|
+
if (settings.username) {
|
|
128
|
+
parsedProxyUrl.username = settings.username;
|
|
129
|
+
}
|
|
130
|
+
if (settings.password) {
|
|
131
|
+
parsedProxyUrl.password = settings.password;
|
|
132
|
+
}
|
|
133
|
+
return parsedProxyUrl;
|
|
134
|
+
}
|
|
135
|
+
function setProxyAgentOnRequest(request, cachedAgents, proxyUrl) {
|
|
110
136
|
// Custom Agent should take precedence so if one is present
|
|
111
137
|
// we should skip to avoid overwriting it.
|
|
112
138
|
if (request.agent) {
|
|
@@ -114,31 +140,21 @@ function setProxyAgentOnRequest(request, cachedAgents) {
|
|
|
114
140
|
}
|
|
115
141
|
const url = new URL(request.url);
|
|
116
142
|
const isInsecure = url.protocol !== "https:";
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
throw new Error(`Expecting a valid host string in proxy settings, but found "${proxySettings.host}".`);
|
|
125
|
-
}
|
|
126
|
-
if (request.tlsSettings) {
|
|
127
|
-
logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
128
|
-
}
|
|
129
|
-
const headers = request.headers.toJSON();
|
|
130
|
-
if (isInsecure) {
|
|
131
|
-
if (!cachedAgents.httpProxyAgent) {
|
|
132
|
-
cachedAgents.httpProxyAgent = new HttpProxyAgent(parsedProxyUrl, { headers });
|
|
133
|
-
}
|
|
134
|
-
request.agent = cachedAgents.httpProxyAgent;
|
|
143
|
+
if (request.tlsSettings) {
|
|
144
|
+
logger.warning("TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.");
|
|
145
|
+
}
|
|
146
|
+
const headers = request.headers.toJSON();
|
|
147
|
+
if (isInsecure) {
|
|
148
|
+
if (!cachedAgents.httpProxyAgent) {
|
|
149
|
+
cachedAgents.httpProxyAgent = new HttpProxyAgent(proxyUrl, { headers });
|
|
135
150
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
request.agent = cachedAgents.httpProxyAgent;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (!cachedAgents.httpsProxyAgent) {
|
|
155
|
+
cachedAgents.httpsProxyAgent = new HttpsProxyAgent(proxyUrl, { headers });
|
|
141
156
|
}
|
|
157
|
+
request.agent = cachedAgents.httpsProxyAgent;
|
|
142
158
|
}
|
|
143
159
|
}
|
|
144
160
|
/**
|
|
@@ -148,20 +164,24 @@ function setProxyAgentOnRequest(request, cachedAgents) {
|
|
|
148
164
|
* @param proxySettings - ProxySettings to use on each request.
|
|
149
165
|
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
150
166
|
*/
|
|
151
|
-
export function proxyPolicy(proxySettings
|
|
167
|
+
export function proxyPolicy(proxySettings, options) {
|
|
152
168
|
if (!noProxyListLoaded) {
|
|
153
169
|
globalNoProxyList.push(...loadNoProxy());
|
|
154
170
|
}
|
|
171
|
+
const defaultProxy = proxySettings
|
|
172
|
+
? getUrlFromProxySettings(proxySettings)
|
|
173
|
+
: getDefaultProxySettingsInternal();
|
|
155
174
|
const cachedAgents = {};
|
|
156
175
|
return {
|
|
157
176
|
name: proxyPolicyName,
|
|
158
177
|
async sendRequest(request, next) {
|
|
159
178
|
if (!request.proxySettings &&
|
|
179
|
+
defaultProxy &&
|
|
160
180
|
!isBypassed(request.url, options?.customNoProxyList ?? globalNoProxyList, options?.customNoProxyList ? undefined : globalBypassedMap)) {
|
|
161
|
-
request
|
|
181
|
+
setProxyAgentOnRequest(request, cachedAgents, defaultProxy);
|
|
162
182
|
}
|
|
163
|
-
if (request.proxySettings) {
|
|
164
|
-
setProxyAgentOnRequest(request, cachedAgents);
|
|
183
|
+
else if (request.proxySettings) {
|
|
184
|
+
setProxyAgentOnRequest(request, cachedAgents, getUrlFromProxySettings(request.proxySettings));
|
|
165
185
|
}
|
|
166
186
|
return next(request);
|
|
167
187
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxyPolicy.js","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQlD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAa,EAAE,CAAC;AAC9C,IAAI,iBAAiB,GAAY,KAAK,CAAC;AAEvC,yDAAyD;AACzD,MAAM,iBAAiB,GAAyB,IAAI,GAAG,EAAE,CAAC;AAE1D,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;SAAM,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QAC3C,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,yBAAyB;IAChC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,UAAU,GAAG,mBAAmB,CAAC,WAAW,CAA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AC,GAAG,WAAW,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,YAAY,GAAiB,EAAE,CAAC;IAEtC,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IACE,CAAC,OAAO,CAAC,aAAa;gBACtB,CAAC,UAAU,CACT,OAAO,CAAC,GAAG,EACX,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAC/C,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAC3D,EACD,CAAC;gBACD,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;YACxC,CAAC;YAED,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBAC1B,sBAAsB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAChD,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as http from \"http\";\nimport type * as https from \"https\";\nimport { HttpsProxyAgent } from \"https-proxy-agent\";\nimport { HttpProxyAgent } from \"http-proxy-agent\";\nimport type {\n PipelineRequest,\n PipelineResponse,\n ProxySettings,\n SendRequest,\n} from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { logger } from \"../log.js\";\n\nconst HTTPS_PROXY = \"HTTPS_PROXY\";\nconst HTTP_PROXY = \"HTTP_PROXY\";\nconst ALL_PROXY = \"ALL_PROXY\";\nconst NO_PROXY = \"NO_PROXY\";\n\n/**\n * The programmatic identifier of the proxyPolicy.\n */\nexport const proxyPolicyName = \"proxyPolicy\";\n\n/**\n * Stores the patterns specified in NO_PROXY environment variable.\n * @internal\n */\nexport const globalNoProxyList: string[] = [];\nlet noProxyListLoaded: boolean = false;\n\n/** A cache of whether a host should bypass the proxy. */\nconst globalBypassedMap: Map<string, boolean> = new Map();\n\nfunction getEnvironmentValue(name: string): string | undefined {\n if (process.env[name]) {\n return process.env[name];\n } else if (process.env[name.toLowerCase()]) {\n return process.env[name.toLowerCase()];\n }\n return undefined;\n}\n\nfunction loadEnvironmentProxyValue(): string | undefined {\n if (!process) {\n return undefined;\n }\n\n const httpsProxy = getEnvironmentValue(HTTPS_PROXY);\n const allProxy = getEnvironmentValue(ALL_PROXY);\n const httpProxy = getEnvironmentValue(HTTP_PROXY);\n\n return httpsProxy || allProxy || httpProxy;\n}\n\n/**\n * Check whether the host of a given `uri` matches any pattern in the no proxy list.\n * If there's a match, any request sent to the same host shouldn't have the proxy settings set.\n * This implementation is a port of https://github.com/Azure/azure-sdk-for-net/blob/8cca811371159e527159c7eb65602477898683e2/sdk/core/Azure.Core/src/Pipeline/Internal/HttpEnvironmentProxy.cs#L210\n */\nfunction isBypassed(\n uri: string,\n noProxyList: string[],\n bypassedMap?: Map<string, boolean>,\n): boolean | undefined {\n if (noProxyList.length === 0) {\n return false;\n }\n const host = new URL(uri).hostname;\n if (bypassedMap?.has(host)) {\n return bypassedMap.get(host);\n }\n let isBypassedFlag = false;\n for (const pattern of noProxyList) {\n if (pattern[0] === \".\") {\n // This should match either domain it self or any subdomain or host\n // .foo.com will match foo.com it self or *.foo.com\n if (host.endsWith(pattern)) {\n isBypassedFlag = true;\n } else {\n if (host.length === pattern.length - 1 && host === pattern.slice(1)) {\n isBypassedFlag = true;\n }\n }\n } else {\n if (host === pattern) {\n isBypassedFlag = true;\n }\n }\n }\n bypassedMap?.set(host, isBypassedFlag);\n return isBypassedFlag;\n}\n\nexport function loadNoProxy(): string[] {\n const noProxy = getEnvironmentValue(NO_PROXY);\n noProxyListLoaded = true;\n if (noProxy) {\n return noProxy\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length);\n }\n\n return [];\n}\n\n/**\n * This method converts a proxy url into `ProxySettings` for use with ProxyPolicy.\n * If no argument is given, it attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n * @param proxyUrl - The url of the proxy to use. May contain authentication information.\n */\nexport function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined {\n if (!proxyUrl) {\n proxyUrl = loadEnvironmentProxyValue();\n if (!proxyUrl) {\n return undefined;\n }\n }\n\n const parsedUrl = new URL(proxyUrl);\n const schema = parsedUrl.protocol ? parsedUrl.protocol + \"//\" : \"\";\n return {\n host: schema + parsedUrl.hostname,\n port: Number.parseInt(parsedUrl.port || \"80\"),\n username: parsedUrl.username,\n password: parsedUrl.password,\n };\n}\n\nfunction setProxyAgentOnRequest(request: PipelineRequest, cachedAgents: CachedAgents): void {\n // Custom Agent should take precedence so if one is present\n // we should skip to avoid overwriting it.\n if (request.agent) {\n return;\n }\n\n const url = new URL(request.url);\n\n const isInsecure = url.protocol !== \"https:\";\n\n const proxySettings = request.proxySettings;\n if (proxySettings) {\n let parsedProxyUrl: URL;\n try {\n parsedProxyUrl = new URL(proxySettings.host);\n } catch (_error) {\n throw new Error(\n `Expecting a valid host string in proxy settings, but found \"${proxySettings.host}\".`,\n );\n }\n\n if (request.tlsSettings) {\n logger.warning(\n \"TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.\",\n );\n }\n\n const headers = request.headers.toJSON();\n\n if (isInsecure) {\n if (!cachedAgents.httpProxyAgent) {\n cachedAgents.httpProxyAgent = new HttpProxyAgent(parsedProxyUrl, { headers });\n }\n request.agent = cachedAgents.httpProxyAgent;\n } else {\n if (!cachedAgents.httpsProxyAgent) {\n cachedAgents.httpsProxyAgent = new HttpsProxyAgent(parsedProxyUrl, { headers });\n }\n request.agent = cachedAgents.httpsProxyAgent;\n }\n }\n}\n\ninterface CachedAgents {\n httpsProxyAgent?: https.Agent;\n httpProxyAgent?: http.Agent;\n}\n\n/**\n * A policy that allows one to apply proxy settings to all requests.\n * If not passed static settings, they will be retrieved from the HTTPS_PROXY\n * or HTTP_PROXY environment variables.\n * @param proxySettings - ProxySettings to use on each request.\n * @param options - additional settings, for example, custom NO_PROXY patterns\n */\nexport function proxyPolicy(\n proxySettings = getDefaultProxySettings(),\n options?: {\n /** a list of patterns to override those loaded from NO_PROXY environment variable. */\n customNoProxyList?: string[];\n },\n): PipelinePolicy {\n if (!noProxyListLoaded) {\n globalNoProxyList.push(...loadNoProxy());\n }\n\n const cachedAgents: CachedAgents = {};\n\n return {\n name: proxyPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (\n !request.proxySettings &&\n !isBypassed(\n request.url,\n options?.customNoProxyList ?? globalNoProxyList,\n options?.customNoProxyList ? undefined : globalBypassedMap,\n )\n ) {\n request.proxySettings = proxySettings;\n }\n\n if (request.proxySettings) {\n setProxyAgentOnRequest(request, cachedAgents);\n }\n return next(request);\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"proxyPolicy.js","sourceRoot":"","sources":["../../../src/policies/proxyPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAQlD,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,UAAU,GAAG,YAAY,CAAC;AAChC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,QAAQ,GAAG,UAAU,CAAC;AAE5B;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAa,EAAE,CAAC;AAC9C,IAAI,iBAAiB,GAAY,KAAK,CAAC;AAEvC,yDAAyD;AACzD,MAAM,iBAAiB,GAAyB,IAAI,GAAG,EAAE,CAAC;AAE1D,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,OAAO,CAAC,GAAG,CAAC,IA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gBACZ,CAAC,UAAU,CACT,OAAO,CAAC,GAAG,EACX,OAAO,EAAE,iBAAiB,IAAI,iBAAiB,EAC/C,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAC3D,EACD,CAAC;gBACD,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC;YAC9D,CAAC;iBAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;gBACjC,sBAAsB,CACpB,OAAO,EACP,YAAY,EACZ,uBAAuB,CAAC,OAAO,CAAC,aAAa,CAAC,CAC/C,CAAC;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport type * as http from \"http\";\nimport type * as https from \"https\";\nimport { HttpsProxyAgent } from \"https-proxy-agent\";\nimport { HttpProxyAgent } from \"http-proxy-agent\";\nimport type {\n PipelineRequest,\n PipelineResponse,\n ProxySettings,\n SendRequest,\n} from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { logger } from \"../log.js\";\n\nconst HTTPS_PROXY = \"HTTPS_PROXY\";\nconst HTTP_PROXY = \"HTTP_PROXY\";\nconst ALL_PROXY = \"ALL_PROXY\";\nconst NO_PROXY = \"NO_PROXY\";\n\n/**\n * The programmatic identifier of the proxyPolicy.\n */\nexport const proxyPolicyName = \"proxyPolicy\";\n\n/**\n * Stores the patterns specified in NO_PROXY environment variable.\n * @internal\n */\nexport const globalNoProxyList: string[] = [];\nlet noProxyListLoaded: boolean = false;\n\n/** A cache of whether a host should bypass the proxy. */\nconst globalBypassedMap: Map<string, boolean> = new Map();\n\nfunction getEnvironmentValue(name: string): string | undefined {\n if (process.env[name]) {\n return process.env[name];\n } else if (process.env[name.toLowerCase()]) {\n return process.env[name.toLowerCase()];\n }\n return undefined;\n}\n\nfunction loadEnvironmentProxyValue(): string | undefined {\n if (!process) {\n return undefined;\n }\n\n const httpsProxy = getEnvironmentValue(HTTPS_PROXY);\n const allProxy = getEnvironmentValue(ALL_PROXY);\n const httpProxy = getEnvironmentValue(HTTP_PROXY);\n\n return httpsProxy || allProxy || httpProxy;\n}\n\n/**\n * Check whether the host of a given `uri` matches any pattern in the no proxy list.\n * If there's a match, any request sent to the same host shouldn't have the proxy settings set.\n * This implementation is a port of https://github.com/Azure/azure-sdk-for-net/blob/8cca811371159e527159c7eb65602477898683e2/sdk/core/Azure.Core/src/Pipeline/Internal/HttpEnvironmentProxy.cs#L210\n */\nfunction isBypassed(\n uri: string,\n noProxyList: string[],\n bypassedMap?: Map<string, boolean>,\n): boolean | undefined {\n if (noProxyList.length === 0) {\n return false;\n }\n const host = new URL(uri).hostname;\n if (bypassedMap?.has(host)) {\n return bypassedMap.get(host);\n }\n let isBypassedFlag = false;\n for (const pattern of noProxyList) {\n if (pattern[0] === \".\") {\n // This should match either domain it self or any subdomain or host\n // .foo.com will match foo.com it self or *.foo.com\n if (host.endsWith(pattern)) {\n isBypassedFlag = true;\n } else {\n if (host.length === pattern.length - 1 && host === pattern.slice(1)) {\n isBypassedFlag = true;\n }\n }\n } else {\n if (host === pattern) {\n isBypassedFlag = true;\n }\n }\n }\n bypassedMap?.set(host, isBypassedFlag);\n return isBypassedFlag;\n}\n\nexport function loadNoProxy(): string[] {\n const noProxy = getEnvironmentValue(NO_PROXY);\n noProxyListLoaded = true;\n if (noProxy) {\n return noProxy\n .split(\",\")\n .map((item) => item.trim())\n .filter((item) => item.length);\n }\n\n return [];\n}\n\n/**\n * This method converts a proxy url into `ProxySettings` for use with ProxyPolicy.\n * If no argument is given, it attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n * @param proxyUrl - The url of the proxy to use. May contain authentication information.\n * @deprecated - Internally this method is no longer necessary when setting proxy information.\n */\nexport function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined {\n if (!proxyUrl) {\n proxyUrl = loadEnvironmentProxyValue();\n if (!proxyUrl) {\n return undefined;\n }\n }\n\n const parsedUrl = new URL(proxyUrl);\n const schema = parsedUrl.protocol ? parsedUrl.protocol + \"//\" : \"\";\n return {\n host: schema + parsedUrl.hostname,\n port: Number.parseInt(parsedUrl.port || \"80\"),\n username: parsedUrl.username,\n password: parsedUrl.password,\n };\n}\n\n/**\n * This method attempts to parse a proxy URL from the environment\n * variables `HTTPS_PROXY` or `HTTP_PROXY`.\n */\nfunction getDefaultProxySettingsInternal(): URL | undefined {\n const envProxy = loadEnvironmentProxyValue();\n return envProxy ? new URL(envProxy) : undefined;\n}\n\nfunction getUrlFromProxySettings(settings: ProxySettings): URL {\n let parsedProxyUrl: URL;\n try {\n parsedProxyUrl = new URL(settings.host);\n } catch (_error) {\n throw new Error(\n `Expecting a valid host string in proxy settings, but found \"${settings.host}\".`,\n );\n }\n\n parsedProxyUrl.port = String(settings.port);\n if (settings.username) {\n parsedProxyUrl.username = settings.username;\n }\n if (settings.password) {\n parsedProxyUrl.password = settings.password;\n }\n\n return parsedProxyUrl;\n}\n\nfunction setProxyAgentOnRequest(\n request: PipelineRequest,\n cachedAgents: CachedAgents,\n proxyUrl: URL,\n): void {\n // Custom Agent should take precedence so if one is present\n // we should skip to avoid overwriting it.\n if (request.agent) {\n return;\n }\n\n const url = new URL(request.url);\n\n const isInsecure = url.protocol !== \"https:\";\n\n if (request.tlsSettings) {\n logger.warning(\n \"TLS settings are not supported in combination with custom Proxy, certificates provided to the client will be ignored.\",\n );\n }\n\n const headers = request.headers.toJSON();\n\n if (isInsecure) {\n if (!cachedAgents.httpProxyAgent) {\n cachedAgents.httpProxyAgent = new HttpProxyAgent(proxyUrl, { headers });\n }\n request.agent = cachedAgents.httpProxyAgent;\n } else {\n if (!cachedAgents.httpsProxyAgent) {\n cachedAgents.httpsProxyAgent = new HttpsProxyAgent(proxyUrl, { headers });\n }\n request.agent = cachedAgents.httpsProxyAgent;\n }\n}\n\ninterface CachedAgents {\n httpsProxyAgent?: https.Agent;\n httpProxyAgent?: http.Agent;\n}\n\n/**\n * A policy that allows one to apply proxy settings to all requests.\n * If not passed static settings, they will be retrieved from the HTTPS_PROXY\n * or HTTP_PROXY environment variables.\n * @param proxySettings - ProxySettings to use on each request.\n * @param options - additional settings, for example, custom NO_PROXY patterns\n */\nexport function proxyPolicy(\n proxySettings?: ProxySettings,\n options?: {\n /** a list of patterns to override those loaded from NO_PROXY environment variable. */\n customNoProxyList?: string[];\n },\n): PipelinePolicy {\n if (!noProxyListLoaded) {\n globalNoProxyList.push(...loadNoProxy());\n }\n\n const defaultProxy = proxySettings\n ? getUrlFromProxySettings(proxySettings)\n : getDefaultProxySettingsInternal();\n\n const cachedAgents: CachedAgents = {};\n\n return {\n name: proxyPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (\n !request.proxySettings &&\n defaultProxy &&\n !isBypassed(\n request.url,\n options?.customNoProxyList ?? globalNoProxyList,\n options?.customNoProxyList ? undefined : globalBypassedMap,\n )\n ) {\n setProxyAgentOnRequest(request, cachedAgents, defaultProxy);\n } else if (request.proxySettings) {\n setProxyAgentOnRequest(\n request,\n cachedAgents,\n getUrlFromProxySettings(request.proxySettings),\n );\n }\n return next(request);\n },\n };\n}\n"]}
|
|
@@ -656,6 +656,7 @@ export declare function getClient(endpoint: string, credentials?: TokenCredentia
|
|
|
656
656
|
* If no argument is given, it attempts to parse a proxy URL from the environment
|
|
657
657
|
* variables `HTTPS_PROXY` or `HTTP_PROXY`.
|
|
658
658
|
* @param proxyUrl - The url of the proxy to use. May contain authentication information.
|
|
659
|
+
* @deprecated - Internally this method is no longer necessary when setting proxy information.
|
|
659
660
|
*/
|
|
660
661
|
export declare function getDefaultProxySettings(proxyUrl?: string): ProxySettings | undefined;
|
|
661
662
|
|
|
@@ -1487,7 +1488,7 @@ export declare interface PipelineRetryOptions {
|
|
|
1487
1488
|
* @param proxySettings - ProxySettings to use on each request.
|
|
1488
1489
|
* @param options - additional settings, for example, custom NO_PROXY patterns
|
|
1489
1490
|
*/
|
|
1490
|
-
export declare function proxyPolicy(proxySettings?: ProxySettings
|
|
1491
|
+
export declare function proxyPolicy(proxySettings?: ProxySettings, options?: {
|
|
1491
1492
|
/** a list of patterns to override those loaded from NO_PROXY environment variable. */
|
|
1492
1493
|
customNoProxyList?: string[];
|
|
1493
1494
|
}): PipelinePolicy;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/ts-http-runtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20240322.2",
|
|
4
4
|
"description": "Isomorphic client library for making HTTP requests in node.js and browser.",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/commonjs/index.js",
|
|
8
8
|
"types": "./dist/commonjs/index.d.ts",
|
|
9
|
+
"browser": "./dist/browser/index.js",
|
|
9
10
|
"exports": {
|
|
10
11
|
"./package.json": "./package.json",
|
|
11
12
|
".": {
|