Merge pull request #105 from gmetais/basic-auth

Basic auth
This commit is contained in:
Gaël Métais
2015-09-14 22:49:29 +02:00
6 changed files with 29 additions and 9 deletions
+3 -1
View File
@@ -33,7 +33,8 @@
.settings select {
font-size: 1em;
}
.settings input[type=text] {
.settings input[type=text],
.settings input[type=password] {
width: 100%;
min-width: 4em;
}
@@ -128,6 +129,7 @@
.advanced > div > div.label {
width: 25%;
white-space: nowrap;
vertical-align: middle;
}
.advanced .subTable {
display: table;
+1 -1
View File
@@ -14,7 +14,7 @@ apiService.factory('API', ['$location', 'Runs', 'Results', function($location, R
waitForSelector: settings.waitForSelector,
cookie: settings.cookie,
authUser: settings.authUser,
authPass: settings.authPass,
authPass: settings.authPass
};
if (settings.waitForSelector && settings.waitForSelector !== '') {
+2 -1
View File
@@ -38,7 +38,7 @@
font-size: 1em;
}
input[type=text] {
input[type=text], input[type=password] {
width: 100%;
min-width: 4em;
}
@@ -147,6 +147,7 @@
&.label {
width: 25%;
white-space: nowrap;
vertical-align: middle;
}
}
}
+3 -3
View File
@@ -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">
@@ -57,10 +57,10 @@
</div>
<div>
<div><span>password</div>
<div><input type="text" class="authField" name="authPass" ng-model="settings.authPass" /></div>
<div><input type="password" class="authField" name="authPass" ng-model="settings.authPass" /></div>
</div>
</div>
</div>-->
</div>
<!--<div>
<div class="label">Blocked domains</div>
<div>
+19 -2
View File
@@ -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 && 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
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') {
+1 -1
View File
@@ -38,7 +38,7 @@
"lwip": "0.0.7",
"meow": "3.3.0",
"minimize": "1.7.0",
"phantomas": "1.11.0",
"phantomas": "1.12.0",
"ps-node": "0.0.4",
"q": "1.4.1",
"request": "2.61.0",