Skip to content

Commit e6f8fac

Browse files
committed
Respect NO_PROXY rules when doing requests
1 parent 9a0859f commit e6f8fac

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/vs/platform/request/node/proxy.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,42 @@ function getSystemProxyURI(requestURL: Url, env: typeof process.env): string | n
1818
return null;
1919
}
2020

21+
function applySystemNoProxyRules(requestURL: Url, proxyURl: string | null, env: typeof process.env): string | null {
22+
const noProxy = env.NO_PROXY || env.no_proxy || null;
23+
if (!noProxy) {
24+
return proxyURl;
25+
}
26+
27+
const rules = noProxy.split(/[\s,]+/);
28+
if (rules[0] === '*') {
29+
return null;
30+
}
31+
32+
for (const rule of rules) {
33+
const ruleMatch = rule.match(/^(.+?)(?::(\d+))?$/);
34+
if (!ruleMatch || !ruleMatch[1]) {
35+
continue;
36+
}
37+
38+
const ruleHost = ruleMatch[1].replace(/^\.*/, '.');
39+
const rulePort = ruleMatch[2];
40+
const requestURLHost = requestURL.hostname!.replace(/^\.*/, '.');
41+
if (requestURLHost.endsWith(ruleHost) && (!rulePort || requestURL.port && requestURL.port === rulePort)) {
42+
return null;
43+
}
44+
}
45+
46+
return proxyURl;
47+
}
48+
2149
export interface IOptions {
2250
proxyUrl?: string;
2351
strictSSL?: boolean;
2452
}
2553

2654
export async function getProxyAgent(rawRequestURL: string, env: typeof process.env, options: IOptions = {}): Promise<Agent> {
2755
const requestURL = parseUrl(rawRequestURL);
28-
const proxyURL = options.proxyUrl || getSystemProxyURI(requestURL, env);
56+
const proxyURL = options.proxyUrl || applySystemNoProxyRules(requestURL, getSystemProxyURI(requestURL, env), env);
2957

3058
if (!proxyURL) {
3159
return null;

0 commit comments

Comments
 (0)