Sha256: 281ce8ea2dd7cdc5f09027a6dbb4ae0e372f886e4a37f17b955698ecfc22c4c7

Contents?: true

Size: 1.7 KB

Versions: 17

Compression:

Stored size: 1.7 KB

Contents

/*!
 * Connect - bodyParser
 * Copyright(c) 2010 Sencha Inc.
 * Copyright(c) 2011 TJ Holowaychuk
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var multipart = require('./multipart')
  , urlencoded = require('./urlencoded')
  , json = require('./json');

/**
 * Body parser:
 *
 *   Status: the multipart body parser will be removed in Connect 3.
 *
 *   Parse request bodies, supports _application/json_,
 *   _application/x-www-form-urlencoded_, and _multipart/form-data_.
 *
 *   This is equivalent to:
 *
 *     app.use(connect.json());
 *     app.use(connect.urlencoded());
 *     app.use(connect.multipart());
 *
 * Examples:
 *
 *      connect()
 *        .use(connect.bodyParser())
 *        .use(function(req, res) {
 *          res.end('viewing user ' + req.body.user.name);
 *        });
 *
 *      $ curl -d 'user[name]=tj' http://local/
 *      $ curl -d '{"user":{"name":"tj"}}' -H "Content-Type: application/json" http://local/
 *
 *  View [json](json.html), [urlencoded](urlencoded.html), and [multipart](multipart.html) for more info.
 *
 *  If you wish to create your own body parser, you may be interested in:
 *
 *    - [raw-body](https://github.com/stream-utils/raw-body)
 *    - [body](https://github.com/raynos/body)
 *
 * @param {Object} options
 * @return {Function}
 * @api public
 */

exports = module.exports = function bodyParser(options){
  var _urlencoded = urlencoded(options)
    , _multipart = multipart(options)
    , _json = json(options);

  return function bodyParser(req, res, next) {
    _json(req, res, function(err){
      if (err) return next(err);
      _urlencoded(req, res, function(err){
        if (err) return next(err);
        _multipart(req, res, next);
      });
    });
  }
};

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/lib/middleware/bodyParser.js