diff --git a/src/index.js b/src/index.js index 009e565..9b21752 100644 --- a/src/index.js +++ b/src/index.js @@ -78,7 +78,7 @@ module.exports = (req, res, logFacilities, config, next) => { } writtenStatusCode = statusCode; let intervene = false; - Object.keys(writtenHeaders).forEach((key) => { + Object.keys(writtenHeaders).every((key) => { if (typeof writtenHeaders[key] == "string") { securityResponse = transaction.addResponseHeader( key, @@ -86,18 +86,20 @@ module.exports = (req, res, logFacilities, config, next) => { ); if (typeof securityResponse === "object") { intervene = true; - return; + return false; } } else if (Array.isArray(writtenHeaders[key])) { - writtenHeaders[key].forEach((value) => { + writtenHeaders[key].every((value) => { securityResponse = transaction.addResponseHeader(key, value); if (typeof securityResponse === "object") { intervene = true; - return; + return false; } + return true; }); - if (intervene) return; + if (intervene) return false; } + return true; }); if (intervene) { res.write = () => false; @@ -267,7 +269,7 @@ module.exports = (req, res, logFacilities, config, next) => { res.write = function (chunk, encoding, callback) { if (!headersSet) { let intervene = false; - Object.keys(writtenHeaders).forEach((key) => { + Object.keys(writtenHeaders).every((key) => { if (typeof writtenHeaders[key] == "string") { securityResponse = transaction.addResponseHeader( key, @@ -275,18 +277,20 @@ module.exports = (req, res, logFacilities, config, next) => { ); if (typeof securityResponse === "object") { intervene = true; - return; + return false; } } else if (Array.isArray(writtenHeaders[key])) { - writtenHeaders[key].forEach((value) => { + writtenHeaders[key].every((value) => { securityResponse = transaction.addResponseHeader(key, value); if (typeof securityResponse === "object") { intervene = true; - return; + return false; } + return true; }); - if (intervene) return; + if (intervene) return false; } + return true; }); if (intervene) { return false;