From 8d12086ababdd23df2710222d426d89b6e515e8e Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 30 Apr 2021 09:34:21 +0530 Subject: [PATCH] check for duplicated headers --- www/checkup/main.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/www/checkup/main.js b/www/checkup/main.js index 68d35a12e..9414c7127 100644 --- a/www/checkup/main.js +++ b/www/checkup/main.js @@ -357,7 +357,7 @@ define([ }); assert(function (cb, msg) { - msg = msg; // XXX + msg = msg; return void cb(true); /* msg.appendChild(h('span', [ @@ -407,6 +407,41 @@ define([ }); }); + var checkDuplicateHeaders = function (url, cb) { + $.ajax(url, { + dataType: 'text', + complete: function (xhr) { + var allHeaders = xhr.getAllResponseHeaders(); + console.error(allHeaders); + var headers = {}; + + var duplicate = allHeaders.split('\n').some(function (header) { + var duplicate; + header.replace(/([^:]+):(.*)/, function (all, type, value) { + type = type.trim(); + if (typeof(headers[type]) !== 'undefined') { + duplicate = true; + } + headers[type] = value.trim(); + }); + return duplicate; + }); + + cb(!duplicate); + }, + }); + }; + + assert(function (cb, msg) { + msg.innerText = "/api/config was served with duplicated headers."; + checkDuplicateHeaders('/api/config', cb); + }); + + assert(function (cb, msg) { + msg.innerText = "/api/config was served with duplicated headers."; + checkDuplicateHeaders('/api/broadcast', cb); + }); + var row = function (cells) { return h('tr', cells.map(function (cell) { return h('td', cell);