Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const opts: any = {}
const len = context.req.headers['content-length']
const encoding = context.req.headers['content-encoding'] || 'identity'
if (len && encoding === 'identity') {
opts.length = +len
}
if (debug) {
console.log(
'fts-http',
'raw-body',
'opts',
JSON.stringify(opts, null, 2)
)
}
const body = await ((raw(
inflate(context.req),
opts
) as unknown) as Promise)
if (debug) {
console.log('fts-http', 'raw-body', body.byteLength, body)
}
return body
}
} else {
let params: any = {}
if (context.req.method === 'GET') {
params = context.query
} else if (context.req.method === 'POST') {
if (context.is('multipart/form-data')) {
const form = new multiparty.Form()
return new Promise((resolve, reject) => {
raw(inflate(req), 'utf-8', (err, body) => {
if (err) {
return reject(err);
} else {
return resolve(body);
}
});
});
};
return new Promise((resolve, reject) => {
raw(inflate(body), 'utf-8', (err, text) => {
if (err) {
return reject(err);
} else {
return resolve(text);
}
});
});
}