refactor: use "every" method instead of "forEach" for checking the written headers with ModSecurity
This commit is contained in:
parent
e4518b934c
commit
27f9eac26f
1 changed files with 14 additions and 10 deletions
24
src/index.js
24
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;
|
||||
|
|
Loading…
Reference in a new issue