Send auth headers with requests
This commit is contained in:
@@ -128,6 +128,7 @@
|
||||
.advanced > div > div.label {
|
||||
width: 25%;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.advanced .subTable {
|
||||
display: table;
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
<div><input type="text" name="cookie" ng-model="settings.cookie" /></div>
|
||||
</div>
|
||||
<!--<div>
|
||||
<div>
|
||||
<div class="label">
|
||||
Authent
|
||||
<span class="settingsTooltip">
|
||||
@@ -60,7 +60,7 @@
|
||||
<div><input type="text" class="authField" name="authPass" ng-model="settings.authPass" /></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>-->
|
||||
</div>
|
||||
<!--<div>
|
||||
<div class="label">Blocked domains</div>
|
||||
<div>
|
||||
|
||||
@@ -24,7 +24,7 @@ var WeightChecker = function() {
|
||||
|
||||
|
||||
// This function will re-download every asset and check if it could be optimized
|
||||
function recheckAllFiles(data) {
|
||||
function recheckAllFiles(data, httpAuth) {
|
||||
var startTime = Date.now();
|
||||
debug('Redownload started');
|
||||
var deferred = Q.defer();
|
||||
@@ -33,11 +33,19 @@ var WeightChecker = function() {
|
||||
delete data.toolsResults.phantomas.metrics.requestsList;
|
||||
delete data.toolsResults.phantomas.offenders.requestsList;
|
||||
|
||||
var httpAuth = null;
|
||||
if (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
|
||||
var redownloadList = requestsList.map(function(entry) {
|
||||
return function(callback) {
|
||||
|
||||
redownloadEntry(entry)
|
||||
redownloadEntry(entry, httpAuth)
|
||||
|
||||
.then(imageOptimizer.optimizeImage)
|
||||
|
||||
@@ -313,7 +321,7 @@ var WeightChecker = function() {
|
||||
}
|
||||
|
||||
|
||||
function redownloadEntry(entry) {
|
||||
function redownloadEntry(entry, httpAuth) {
|
||||
var deferred = Q.defer();
|
||||
|
||||
function downloadError(message) {
|
||||
@@ -367,6 +375,15 @@ var WeightChecker = function() {
|
||||
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) {
|
||||
if (error) {
|
||||
if (error.code === 'ETIMEDOUT') {
|
||||
|
||||
Reference in New Issue
Block a user