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

Commit

Permalink
feat(webdriver-manager): minor proxy enhancements
Browse files Browse the repository at this point in the history
Added error handling for request - previously, any errors coming from
the request module were silently swallowed.

Fixed error handling to remove empty files when a download fails for
some reason.

Instead of throwing an error as an exception, the error is simply logged
and then the rest of the code continues. Previously, the uncaught
exceptions caused the program to stop immediately, without any chance of
recovering, or finishing other downloads. With the previous code, any
other downloads at the same time were interrupted, resulting in empty
files or incomplete downloads.

Logging the errors instead of throwing will allow the other downloads to
finish, and it will also allow removing empty files resulting from a
failed download, e.g. when no internet connection is available or with
an invalid proxy configuration.

Also evaluating both uppercase and lowercase proxy variables. Many tools
use proxy variables in the form https_proxy, others use HTTPS_PROXY. I
changed the code so both forms are evaluated. See the following links
for more info on this practice:

* http://serverfault.com/q/571887/140074
* https://wiki.archlinux.org/index.php/proxy_settings#Environment_variables
  • Loading branch information
nwinkler authored and hankduan committed Jun 25, 2014
1 parent dbf7ab5 commit 62bcf7e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/webdriver-manager
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ var resolveProxy = function(fileUrl) {
if (argv.proxy) {
return argv.proxy;
} else if (protocol === 'https:') {
return process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
} else if (protocol === 'http:') {
return process.env.HTTP_PROXY;
return process.env.HTTP_PROXY || process.env.http_proxy;
}
};

Expand All @@ -132,8 +132,15 @@ var httpGetFile = function(fileUrl, fileName, outputDir, callback) {
proxy: resolveProxy(fileUrl)
}
request(options, function (error, response) {
if (error) {
fs.unlink(filePath);
console.error('Error: Got error ' + error + ' from ' + fileUrl);
return;
}
if (response.statusCode !== 200) {
throw new Error('Got code ' + response.statusCode + ' from ' + fileUrl);
fs.unlink(filePath);
console.error('Error: Got code ' + response.statusCode + ' from ' + fileUrl);
return;
}
console.log(fileName + ' downloaded to ' + filePath);
if (callback) {
Expand Down

0 comments on commit 62bcf7e

Please sign in to comment.