Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit de4b33e

Browse files
dsebastiencnishina
authored andcommitted
feat(webdriver): Added NO_PROXY environment variable support to webdriver-manager
closes #3046
1 parent a0c5209 commit de4b33e

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

bin/webdriver-manager

+34-9
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,40 @@ if (!fs.existsSync(argv.out_dir) || !fs.statSync(argv.out_dir).isDirectory()) {
173173
fs.mkdirSync(argv.out_dir);
174174
}
175175

176-
var resolveProxy = function(fileUrl) {
177-
var protocol = url.parse(fileUrl).protocol;
178-
if (argv.proxy) {
179-
return argv.proxy;
180-
} else if (protocol === 'https:') {
181-
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
182-
} else if (protocol === 'http:') {
183-
return process.env.HTTP_PROXY || process.env.http_proxy;
184-
}
176+
var resolveProxy = function (fileUrl) {
177+
var parsedUrl = url.parse(fileUrl);
178+
var protocol = parsedUrl.protocol;
179+
var hostname = parsedUrl.hostname;
180+
181+
if (argv.proxy) {
182+
// if a proxy was explicitly specified, then it must be used
183+
return argv.proxy;
184+
} else {
185+
// NO_PROXY environment variable
186+
var noProxy = process.env.NO_PROXY || process.env.no_proxy || "";
187+
noProxy = noProxy.replace(/\s/g, ''); // remove spaces
188+
189+
// array of hostnames/domain names listed in the NO_PROXY environment variable
190+
var noProxyTokens = noProxy.split(",");
191+
// avoid the non-empty array with an empty string (i.e., if not defined or empty: no tokens to check for)
192+
if (noProxyTokens[0] === "") {
193+
noProxyTokens = [];
194+
}
195+
196+
// check if the fileUrl hostname part does not end with one of the NO_PROXY environment variable's hostnames/domain names
197+
for(var noProxyIndex = 0; noProxyIndex < noProxyTokens.length; ++noProxyIndex) {
198+
var noProxyToken = noProxyTokens[noProxyIndex];
199+
if (hostname.indexOf(noProxyToken, hostname.length - noProxyToken.length) !== -1) {
200+
return null; // no proxy should be used!
201+
}
202+
}
203+
204+
if (protocol === 'https:') {
205+
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
206+
} else if (protocol === 'http:') {
207+
return process.env.HTTP_PROXY || process.env.http_proxy;
208+
}
209+
}
185210
};
186211

187212
/**

0 commit comments

Comments
 (0)