fkc
Version:
FKC application service framework.
20 lines • 636 B
JavaScript
;
module.exports = (req,obj)=>{
let body='';
req.setEncoding("utf-8");
return new Promise((resolve) => {
req.on("data", (data) => {
body += data.toString();
if(obj.KB&&obj.KB>0&&Buffer.byteLength(body,'utf8')>obj.KB*1024) req.destroy();
})
req.on('close', () => {
if(obj.err) obj.err('Beyond '+obj.KB+' KB');
resolve(null);
});
req.on('end',()=>{
if(obj.err) obj.err(null);
if(obj.type==='urlencoded') body = decodeURIComponent(body);
resolve(body);
})
})
}