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;
|
writtenStatusCode = statusCode;
|
||||||
let intervene = false;
|
let intervene = false;
|
||||||
Object.keys(writtenHeaders).forEach((key) => {
|
Object.keys(writtenHeaders).every((key) => {
|
||||||
if (typeof writtenHeaders[key] == "string") {
|
if (typeof writtenHeaders[key] == "string") {
|
||||||
securityResponse = transaction.addResponseHeader(
|
securityResponse = transaction.addResponseHeader(
|
||||||
key,
|
key,
|
||||||
|
@ -86,18 +86,20 @@ module.exports = (req, res, logFacilities, config, next) => {
|
||||||
);
|
);
|
||||||
if (typeof securityResponse === "object") {
|
if (typeof securityResponse === "object") {
|
||||||
intervene = true;
|
intervene = true;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (Array.isArray(writtenHeaders[key])) {
|
} else if (Array.isArray(writtenHeaders[key])) {
|
||||||
writtenHeaders[key].forEach((value) => {
|
writtenHeaders[key].every((value) => {
|
||||||
securityResponse = transaction.addResponseHeader(key, value);
|
securityResponse = transaction.addResponseHeader(key, value);
|
||||||
if (typeof securityResponse === "object") {
|
if (typeof securityResponse === "object") {
|
||||||
intervene = true;
|
intervene = true;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
if (intervene) return;
|
if (intervene) return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
if (intervene) {
|
if (intervene) {
|
||||||
res.write = () => false;
|
res.write = () => false;
|
||||||
|
@ -267,7 +269,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
||||||
res.write = function (chunk, encoding, callback) {
|
res.write = function (chunk, encoding, callback) {
|
||||||
if (!headersSet) {
|
if (!headersSet) {
|
||||||
let intervene = false;
|
let intervene = false;
|
||||||
Object.keys(writtenHeaders).forEach((key) => {
|
Object.keys(writtenHeaders).every((key) => {
|
||||||
if (typeof writtenHeaders[key] == "string") {
|
if (typeof writtenHeaders[key] == "string") {
|
||||||
securityResponse = transaction.addResponseHeader(
|
securityResponse = transaction.addResponseHeader(
|
||||||
key,
|
key,
|
||||||
|
@ -275,18 +277,20 @@ module.exports = (req, res, logFacilities, config, next) => {
|
||||||
);
|
);
|
||||||
if (typeof securityResponse === "object") {
|
if (typeof securityResponse === "object") {
|
||||||
intervene = true;
|
intervene = true;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (Array.isArray(writtenHeaders[key])) {
|
} else if (Array.isArray(writtenHeaders[key])) {
|
||||||
writtenHeaders[key].forEach((value) => {
|
writtenHeaders[key].every((value) => {
|
||||||
securityResponse = transaction.addResponseHeader(key, value);
|
securityResponse = transaction.addResponseHeader(key, value);
|
||||||
if (typeof securityResponse === "object") {
|
if (typeof securityResponse === "object") {
|
||||||
intervene = true;
|
intervene = true;
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
if (intervene) return;
|
if (intervene) return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
if (intervene) {
|
if (intervene) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue