Skip to content

Commit

Permalink
Changed: json() and urlencoded() allow empty bodies. Closes senchalab…
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Dec 21, 2011
1 parent 7b4bcec commit f294eb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/middleware/json.js
Expand Up @@ -42,7 +42,9 @@ exports = module.exports = function(options){
req.on('data', function(chunk){ buf += chunk });
req.on('end', function(){
try {
req.body = JSON.parse(buf);
req.body = buf.length
? JSON.parse(buf)
: {};
next();
} catch (err){
err.status = 400;
Expand Down
4 changes: 3 additions & 1 deletion lib/middleware/urlencoded.js
Expand Up @@ -43,7 +43,9 @@ exports = module.exports = function(options){
req.on('data', function(chunk){ buf += chunk });
req.on('end', function(){
try {
req.body = qs.parse(buf);
req.body = buf.length
? qs.parse(buf)
: {};
next();
} catch (err){
next(err);
Expand Down

0 comments on commit f294eb8

Please sign in to comment.