Skip to content

Commit

Permalink
Respect NO_PROXY rules when doing requests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanp413 committed Apr 18, 2022
1 parent 3843789 commit 45cc112
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/vs/platform/request/node/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,42 @@ function getSystemProxyURI(requestURL: Url, env: typeof process.env): string | n
return null;
}

function applySystemNoProxyRules(requestURL: Url, proxyURl: string | null, env: typeof process.env): string | null {
const noProxy = env.NO_PROXY || env.no_proxy || null;
if (!noProxy) {
return proxyURl;
}

const rules = noProxy.split(/[\s,]+/);
if (rules[0] === '*') {
return null;
}

for (const rule of rules) {
const ruleMatch = rule.match(/^(.+?)(?::(\d+))?$/);
if (!ruleMatch || !ruleMatch[1]) {
continue;
}

const ruleHost = ruleMatch[1].replace(/^\.*/, '.');
const rulePort = ruleMatch[2];
const requestURLHost = requestURL.hostname!.replace(/^\.*/, '.');
if (requestURLHost.endsWith(ruleHost) && (!rulePort || requestURL.port && requestURL.port === rulePort)) {
return null;
}
}

return proxyURl;
}

export interface IOptions {
proxyUrl?: string;
strictSSL?: boolean;
}

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

if (!proxyURL) {
return null;
Expand Down

0 comments on commit 45cc112

Please sign in to comment.