|
@@ -33,11 +33,19 @@ var WeightChecker = function() {
|
|
delete data.toolsResults.phantomas.metrics.requestsList;
|
|
delete data.toolsResults.phantomas.metrics.requestsList;
|
|
delete data.toolsResults.phantomas.offenders.requestsList;
|
|
delete data.toolsResults.phantomas.offenders.requestsList;
|
|
|
|
|
|
|
|
+ var httpAuth = null;
|
|
|
|
+ if (data.params && data.params.options && data.params.options.authUser && data.params.options.authPass) {
|
|
|
|
+ httpAuth = {
|
|
|
|
+ username: data.params.options.authUser,
|
|
|
|
+ password: data.params.options.authPass
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
// Transform every request into a download function with a callback when done
|
|
// Transform every request into a download function with a callback when done
|
|
var redownloadList = requestsList.map(function(entry) {
|
|
var redownloadList = requestsList.map(function(entry) {
|
|
return function(callback) {
|
|
return function(callback) {
|
|
|
|
|
|
- redownloadEntry(entry)
|
|
|
|
|
|
+ redownloadEntry(entry, httpAuth)
|
|
|
|
|
|
.then(imageOptimizer.optimizeImage)
|
|
.then(imageOptimizer.optimizeImage)
|
|
|
|
|
|
@@ -313,7 +321,7 @@ var WeightChecker = function() {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- function redownloadEntry(entry) {
|
|
|
|
|
|
+ function redownloadEntry(entry, httpAuth) {
|
|
var deferred = Q.defer();
|
|
var deferred = Q.defer();
|
|
|
|
|
|
function downloadError(message) {
|
|
function downloadError(message) {
|
|
@@ -367,6 +375,15 @@ var WeightChecker = function() {
|
|
timeout: REQUEST_TIMEOUT
|
|
timeout: REQUEST_TIMEOUT
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ // Basic auth
|
|
|
|
+ if (httpAuth) {
|
|
|
|
+ requestOptions.auth = {
|
|
|
|
+ user: httpAuth.username,
|
|
|
|
+ pass: httpAuth.password,
|
|
|
|
+ sendImmediately: false // Tries a first time without auth, wait for a 401 error before resending
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
download(requestOptions, entry.contentType, function(error, result) {
|
|
download(requestOptions, entry.contentType, function(error, result) {
|
|
if (error) {
|
|
if (error) {
|
|
if (error.code === 'ETIMEDOUT') {
|
|
if (error.code === 'ETIMEDOUT') {
|