@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
34 lines (33 loc) • 1.06 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBodyDataType = getBodyDataType;
const isJsonContentType_1 = require("../../helpers/isJsonContentType");
/**
* Tries to determine the type of the body data based on the content type header.
*/
function getBodyDataType(headers) {
if (typeof headers !== "object" || headers === null) {
return;
}
let contentType = headers["content-type"];
if (!contentType) {
return;
}
if (Array.isArray(contentType)) {
// Choose the first content type if there are multiple, express will discard duplicates
contentType = contentType[0];
}
if ((0, isJsonContentType_1.isJsonContentType)(contentType)) {
return "json";
}
if (contentType.startsWith("application/x-www-form-urlencoded")) {
return "form-urlencoded";
}
if (contentType.startsWith("multipart/form-data")) {
return "form-data";
}
if (contentType.includes("xml")) {
return "xml";
}
return undefined;
}
;