I am requesting a rest server from nodejs by using nodejs request module.is it possible to determine the size of the data that will be returned to me (before accepting the data)?I want to cancel the operation if the size of the data that will be returned to me is more than the amount I determines.the purpose here is to ensure that my network is not locked.
My request part as follows;
const request = registry.get("requestPromiseNative");
const logger = registry.get("logger");
let env = registry.get("env");
class SmartContractFetch {
constructor() {
this.dataSizeFetched = 0; //in bytes
}
async fetchData(method, url, data = {}, header = {}) {
try {
logger.info("Smart contract fetch işlemi başladı.");
if (method.toUpperCase() === "POST") {
console.log("POS içinde : " + JSON.stringify(data));
let response = await request.post({
url: url,
resolveWithFullResponse: true,
form: data,
headers: header
});
let responseJSON = JSON.parse(response.body);
this.dataSizeFetched += response.body.length;
logger.info(
"Smart contract fetch işlemi başarıyla tamamlandı. Gelen Data : " +
responseJSON
);
return responseJSON;
} else if (method.toUpperCase() === "GET") {
console.log("GET içinde : " + JSON.stringify(data));
let response = await request.get({
url: url,
resolveWithFullResponse: true,
form: data,
headers: header
});
this.dataSizeFetched += response.body.length;
let responseJSON = JSON.parse(response.body);
logger.info(
"Smart contract fetch işlemi başarıyla tamamlandı. Gelen Data : " +
responseJSON
);
return responseJSON;
}
} catch (error) {
logger.error(
"Smart contract fetch işlemi başarısız. Sonuç : " + error.message
);
throw new Error(error);
}
}
}
module.exports = SmartContractFetch;