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

Commit 6249efe

Browse files
cesarandreujuliemr
authored andcommitted
fix(webdriver-manager): use request module instead of http
Google changed selenium-server-standalone.jar's location and is returning 302 http module does not follow redirects Closes #826
1 parent e3731f7 commit 6249efe

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

bin/webdriver-manager

+18-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var fs = require('fs');
44
var os = require('os');
5-
var url = require('url');
5+
var request = require('request');
66
var http = require('http');
77
var path = require('path');
88
var AdmZip = require('adm-zip');
@@ -107,32 +107,28 @@ if (!fs.existsSync(argv.out_dir) || !fs.statSync(argv.out_dir).isDirectory()) {
107107

108108
/**
109109
* Function to download file using HTTP.get.
110-
* Thanks to http://www.hacksparrow.com/using-node-js-to-download-files.html
111-
* for the outline of this code.
110+
* TODO: look into using something instead of request here, to avoid the
111+
* big dependency cost. It's required for now to follow redirects.
112112
*/
113113
var httpGetFile = function(fileUrl, fileName, outputDir, callback) {
114114
console.log('downloading ' + fileUrl + '...');
115-
var options = {
116-
host: url.parse(fileUrl).host,
117-
port: 80,
118-
path: url.parse(fileUrl).pathname
119-
};
120-
121-
http.get(options, function(res) {
115+
var filePath = path.join(outputDir, fileName);
116+
var file = fs.createWriteStream(filePath);
117+
var req = request(fileUrl);
118+
req.on('response', function(res) {
122119
if (res.statusCode !== 200) {
123120
throw new Error('Got code ' + res.statusCode + ' from ' + fileUrl);
124-
}
125-
var filePath = path.join(outputDir, fileName);
126-
var file = fs.createWriteStream(filePath);
127-
res.on('data', function(data) {
128-
file.write(data);
129-
}).on('end', function() {
130-
file.end(function() {
131-
console.log(fileName + ' downloaded to ' + filePath);
132-
if (callback) {
133-
callback(filePath);
134-
}
135-
});
121+
}
122+
});
123+
req.on('data', function(data) {
124+
file.write(data);
125+
});
126+
req.on('end', function() {
127+
file.end(function() {
128+
console.log(fileName + ' downloaded to ' + filePath);
129+
if (callback) {
130+
callback(filePath);
131+
}
136132
});
137133
});
138134
};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
],
1313
"author": "Julie Ralph <[email protected]>",
1414
"dependencies": {
15+
"request": "^2.36.0",
1516
"selenium-webdriver": "2.41.0",
1617
"minijasminenode": "0.4.0",
1718
"saucelabs": "~0.1.0",

0 commit comments

Comments
 (0)