display more information about incorrect headers on checkup page

pull/1/head
ansuz 4 years ago
parent 4c91bb83d0
commit 2ed25c38fb

@ -424,7 +424,11 @@ define([
}); });
}); });
var checkAPIHeaders = function (url, cb) { var code = function (content) {
return h('code', content);
};
var checkAPIHeaders = function (url, msg, cb) {
$.ajax(url, { $.ajax(url, {
dataType: 'text', dataType: 'text',
complete: function (xhr) { complete: function (xhr) {
@ -446,14 +450,29 @@ define([
'cross-origin-resource-policy': 'cross-origin', 'cross-origin-resource-policy': 'cross-origin',
'cross-origin-embedder-policy': 'require-corp', 'cross-origin-embedder-policy': 'require-corp',
}; };
var incorrect = Object.keys(expect).some(function (k) { var incorrect = false;
Object.keys(expect).forEach(function (k) {
var response = xhr.getResponseHeader(k); var response = xhr.getResponseHeader(k);
if (response !== expect[k]) { var expected = expect[k];
return true; if (response !== expected) {
incorrect = true;
msg.appendChild(h('p', [
'The ',
code(k),
' header for ',
code(url),
" is '",
code(response),
"' instead of '",
code(expected),
"' as expected.",
]));
} }
}); });
if (duplicated || incorrect) { console.error(allHeaders); } if (duplicated || incorrect) { console.debug(allHeaders); }
cb(!duplicated && !incorrect); cb(!duplicated && !incorrect);
}, },
}); });
@ -464,13 +483,13 @@ define([
assert(function (cb, msg) { assert(function (cb, msg) {
var url = '/api/config'; var url = '/api/config';
msg.innerText = url + INCORRECT_HEADER_TEXT; msg.innerText = url + INCORRECT_HEADER_TEXT;
checkAPIHeaders(url, cb); checkAPIHeaders(url, msg, cb);
}); });
assert(function (cb, msg) { assert(function (cb, msg) {
var url = '/api/broadcast'; var url = '/api/broadcast';
msg.innerText = url + INCORRECT_HEADER_TEXT; msg.innerText = url + INCORRECT_HEADER_TEXT;
checkAPIHeaders(url, cb); checkAPIHeaders(url, msg, cb);
}); });
var setWarningClass = function (msg) { var setWarningClass = function (msg) {

Loading…
Cancel
Save