@hclsoftware/secagent
Version:
IAST agent
56 lines (44 loc) • 1.47 kB
JavaScript
//IASTIGNORE
/*
* ****************************************************
* Licensed Materials - Property of HCL.
* (c) Copyright HCL Technologies Ltd. 2017, 2025.
* Note to U.S. Government Users *Restricted Rights.
* ****************************************************
*/
const Type = Object.freeze({
TEXT: "text",
JSON: "json",
BINARY: "binary",
})
class RequestBody {
constructor(contentType) {
this.contentType = contentType != null ? contentType.origToLowerCase() : ""
this.data = null
}
getReportingJson() {
if (this.data == null || (typeof this.data === 'object' && Object.keys(this.data).length === 0)) {
return null
}
else if (typeof this.data === 'string' || this.data instanceof String) {
try {
const bodyAsJson = JSON.origParse(this.data)
return {type: Type.JSON, value: bodyAsJson}
}
catch (e) {
return {type: Type.TEXT, value: this.data}
}
}
else if (typeof this.data === 'object') {
if (this.contentType.origStringIncludes("json")) {
return {type: Type.JSON, value: this.data}
}
else {
return {type: Type.BINARY}
}
}
return null
}
}
module.exports.RequestBody = RequestBody
module.exports.Type = Type