Skip to content

Commit

Permalink
imp - length
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperhsiung committed Nov 22, 2018
1 parent b0db7c6 commit 0c64396
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions lib/reply.js
Expand Up @@ -16,25 +16,25 @@ module.exports = function(req, _, done) {
let length = Buffer.byteLength(data);
req.data = data;
// simply infer content type
if (length < 1000) {
data = data.toString();
try {
if (type.includes('json')) {
req.body = parse.json(data);
}
if (type.includes('form-urlencoded')) {
req.body = parse.query(data);
}
if (type.includes('form-data')) {
req.body = parse.bound(data);
}
if (type.includes('plain')) {
req.body = data;
}
} catch (e) {
console.error(e);
// if (length < 1000) {
data = data.toString();
try {
if (type.includes('json')) {
req.body = parse.json(data);
}
if (type.includes('form-urlencoded')) {
req.body = parse.query(data);
}
if (type.includes('form-data')) {
req.body = parse.bound(data);
}
if (type.includes('plain')) {
req.body = data;
}
} catch (e) {
console.error(e);
}
// }
req.param = Object.assign({}, req.query, typeof req.body === 'object' ? req.body : {});
done();
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "restar",
"version": "2.0.7",
"version": "2.0.8",
"description": "web library for rest api",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 0c64396

Please sign in to comment.