Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Change talked about in #354 #368

Merged
merged 3 commits into from

2 participants

@ryanrolds

Preforms check to see if req.body is already populated. If so, move on to the next middleware. If req.body isn't set the set it and attempt to parse the message body as usual.

@tj tj merged commit 32bee2d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 11, 2011
  1. @ryanrolds
Commits on Sep 14, 2011
  1. @ryanrolds
Commits on Sep 15, 2011
  1. @ryanrolds

    Default req.body to {} per #354

    ryanrolds authored
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 3 deletions.
  1. +4 −1 lib/middleware/bodyParser.js
  2. +2 −2 test/bodyParser.test.js
View
5 lib/middleware/bodyParser.js
@@ -56,9 +56,12 @@ function mime(req) {
exports = module.exports = function bodyParser(){
return function bodyParser(req, res, next) {
+ if (req.body) return next();
+ req.body = {};
+
if ('GET' == req.method || 'HEAD' == req.method) return next();
var parser = exports.parse[mime(req)];
- if (parser && !req.body) {
+ if (parser) {
var data = '';
req.setEncoding('utf8');
req.on('data', function(chunk) { data += chunk; });
View
4 test/bodyParser.test.js
@@ -46,13 +46,13 @@ module.exports = {
'test POST with no data': function(){
assert.response(app,
{ url: '/', method: 'POST' },
- { body: '' });
+ { body: '{}' });
},
'test GET with content-type': function(){
assert.response(app,
{ url: '/', headers: { 'Content-Type': 'application/json' }},
- { body: '' });
+ { body: '{}' });
},
'test custom parser': function(){
Something went wrong with that request. Please try again.