UNPKG

@hclsoftware/secagent

Version:

IAST agent

61 lines (49 loc) 1.61 kB
//IASTIGNORE /* * **************************************************** * Licensed Materials - Property of HCL. * (c) Copyright HCL Technologies Ltd. 2017, 2025. * Note to U.S. Government Users *Restricted Rights. * **************************************************** */ const StackInfo = require("../StackInfo") const Utils = require("../Utils/Utils") 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 } let ret = null if (typeof this.data === 'string' || this.data instanceof String) { if (Utils.isJSONStr(this.data)) { ret = {type: Type.JSON, value: this.data} } else { ret = {type: Type.TEXT, value: this.data} } } else if (typeof this.data === 'object') { if (this.contentType.origStringIncludes("json")) { ret = {type: Type.JSON, value: JSON.origStringify(this.data)} } else { ret = {type: Type.BINARY} } } if (ret != null && ret.value != null) { ret.value = StackInfo.asString(ret.value) } return ret } } module.exports.RequestBody = RequestBody module.exports.Type = Type