Bug 1255425 - part 1 - clearly delineate steps when outputting HSTS preload list; r=keeler

The main loop of |output| tweaks entries, filters out entries based on
some conditions, and writes out the actual entries we're going to use.
Let's separate those three steps so it's clearer what's happening where.
This commit is contained in:
Nathan Froyd 2016-03-11 15:35:47 -05:00
Родитель 1277f4579f
Коммит b2490bf812
1 изменённых файлов: 17 добавлений и 10 удалений

Просмотреть файл

@ -259,8 +259,8 @@ function output(sortedStatuses, currentList) {
writeTo(HEADER, fos);
writeTo(getExpirationTimeString(), fos);
writeTo(PREFIX, fos);
for (var status of sortedStatuses) {
for (let status in sortedStatuses) {
// If we've encountered an error for this entry (other than the site not
// sending an HSTS header), be safe and don't remove it from the list
// (given that it was already on the list).
@ -273,19 +273,26 @@ function output(sortedStatuses, currentList) {
status.maxAge = MINIMUM_REQUIRED_MAX_AGE;
status.includeSubdomains = currentList[status.name];
}
}
if (status.maxAge >= MINIMUM_REQUIRED_MAX_AGE || status.forceInclude) {
writeEntry(status, fos);
dump("INFO: " + status.name + " ON the preload list\n");
if (status.forceInclude && status.error != ERROR_NONE) {
writeTo(status.name + ": " + errorToString(status) + " (error "
+ "ignored - included regardless)\n", eos);
}
}
else {
// Filter out entries we aren't including.
var includedStatuses = sortedStatuses.filter(function (status) {
if (status.maxAge < MINIMUM_REQUIRED_MAX_AGE && !status.forceInclude) {
dump("INFO: " + status.name + " NOT ON the preload list\n");
writeTo(status.name + ": " + errorToString(status) + "\n", eos);
return false;
}
dump("INFO: " + status.name + " ON the preload list\n");
if (status.forceInclude && status.error != ERROR_NONE) {
writeTo(status.name + ": " + errorToString(status) + " (error "
+ "ignored - included regardless)\n", eos);
}
return true;
});
for (var status of includedStatuses) {
writeEntry(status, fos);
}
writeTo(POSTFIX, fos);
FileUtils.closeSafeFileOutputStream(fos);