Permalink
Browse files

remove body parser and various cleanup

  • Loading branch information...
1 parent c8801e6 commit 5c5e81fa31c5a55a06c334b7285a4f5c2dc28b75 @jonathanong jonathanong committed Jan 6, 2014
View
@@ -1,39 +1,19 @@
TESTS = test/*.js
REPORTER = dot
-DOX = ./node_modules/.bin/dox
-
-SRC = $(shell find lib/*.js lib/middleware/*.js)
-HTML = $(SRC:.js=.html)
test:
@NODE_ENV=test ./node_modules/.bin/mocha \
--reporter $(REPORTER) \
$(TESTS)
-docs: $(HTML)
- @mv $(HTML) docs
-
test-cov: lib-cov
@CONNECT_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html
lib-cov:
@jscoverage lib $@
-%.html: %.js
- $(DOX) < $< | node support/docs > $@
-
-docclean:
- rm -f $(HTML)
-
-site: docclean docs
- rm -fr /tmp/docs \
- && cp -fr docs /tmp/docs \
- && git checkout gh-pages \
- && cp -fr /tmp/docs/* . \
- && echo "done"
-
benchmark:
@./support/bench
-.PHONY: test-cov site docs test docclean benchmark
+.PHONY: test-cov test benchmark
View
@@ -32,6 +32,10 @@ If you would like to help maintain these middleware, please contact [@jongleberr
These middleware are officially supported by the Connect/Express team:
+ - [body-parser](https://github.com/expressjs/body-parser) - previous `bodyParser`, `json`, and `urlencoded`. You may also be interested in:
+ - [body](https://github.com/raynos/body)
+ - [co-body](https://github.com/visionmedia/co-body)
+ - [raw-body](https://github.com/stream-utils/raw-body)
- [compression](https://github.com/expressjs/compression) - previously `compress`
These middleware previously included with Connect are no longer supported by the Connect/Express team. Use one of these alternatives intead:
View
@@ -25,18 +25,6 @@ require('./patch');
exports = module.exports = createServer;
/**
- * Framework version.
- */
-
-exports.version = '2.7.11';
-
-/**
- * Expose mime module.
- */
-
-exports.mime = require('./middleware/static').mime;
-
-/**
* Expose the prototype.
*/
@@ -1,63 +0,0 @@
-
-/*!
- * Connect - bodyParser
- * Copyright(c) 2010 Sencha Inc.
- * Copyright(c) 2011 TJ Holowaychuk
- * MIT Licensed
- */
-
-/**
- * Module dependencies.
- */
-
-var urlencoded = require('./urlencoded');
-var 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);
- var _json = json(options);
-
- return function bodyParser(req, res, next) {
- _json(req, res, function(err){
- if (err) return next(err);
- _urlencoded(req, res, next);
- });
- }
-};
View
@@ -1,87 +0,0 @@
-
-/*!
- * Connect - json
- * Copyright(c) 2010 Sencha Inc.
- * Copyright(c) 2011 TJ Holowaychuk
- * MIT Licensed
- */
-
-/**
- * Module dependencies.
- */
-
-var utils = require('../utils');
-var getBody = require('raw-body');
-
-/**
- * JSON:
- *
- * Parse JSON request bodies, providing the
- * parsed object as `req.body`.
- *
- * Options:
- *
- * - `strict` when `false` anything `JSON.parse()` accepts will be parsed
- * - `reviver` used as the second "reviver" argument for JSON.parse
- * - `limit` byte limit [1mb]
- *
- * @param {Object} options
- * @return {Function}
- * @api public
- */
-
-exports = module.exports = function(options){
- options = options || {};
- var strict = options.strict !== false;
- var verify = typeof options.verify === 'function' && options.verify;
-
- return function json(req, res, next) {
- if (req._body) return next();
- req.body = req.body || {};
-
- if (!utils.hasBody(req)) return next();
-
- // check Content-Type
- if (!exports.regexp.test(utils.mime(req))) return next();
-
- // flag as parsed
- req._body = true;
-
- // parse
- getBody(req, {
- limit: options.limit || '1mb',
- length: req.headers['content-length'],
- encoding: 'utf8'
- }, function (err, buf) {
- if (err) return next(err);
-
- if (verify) {
- try {
- verify(req, res, buf)
- } catch (err) {
- if (!err.status) err.status = 403;
- return next(err);
- }
- }
-
- var first = buf.trim()[0];
-
- if (0 == buf.length) {
- return next(utils.error(400, 'invalid json, empty body'));
- }
-
- if (strict && '{' != first && '[' != first) return next(utils.error(400, 'invalid json'));
- try {
- req.body = JSON.parse(buf, options.reviver);
- } catch (err){
- err.body = buf;
- err.status = 400;
- return next(err);
- }
- next();
- })
- };
-};
-
-exports.regexp = /^application\/([\w!#\$%&\*`\-\.\^~]*\+)?json$/i;
-
View
@@ -85,12 +85,3 @@ exports = module.exports = function(root, options){
.pipe(res);
};
};
-
-/**
- * Expose mime module.
- *
- * If you wish to extend the mime table use this
- * reference to the "mime" module in the npm registry.
- */
-
-exports.mime = send.mime;
@@ -1,76 +0,0 @@
-/*!
- * Connect - urlencoded
- * Copyright(c) 2010 Sencha Inc.
- * Copyright(c) 2011 TJ Holowaychuk
- * MIT Licensed
- */
-
-/**
- * Module dependencies.
- */
-
-var utils = require('../utils');
-var getBody = require('raw-body');
-var qs = require('qs');
-
-/**
- * Urlencoded:
- *
- * Parse x-ww-form-urlencoded request bodies,
- * providing the parsed object as `req.body` using
- * [qs](https://github.com/visionmedia/node-querystring).
- *
- * Options:
- *
- * - `limit` byte limit [1mb]
- *
- * @param {Object} options
- * @return {Function}
- * @api public
- */
-
-exports = module.exports = function(options){
- options = options || {};
- var verify = typeof options.verify === 'function' && options.verify;
-
- return function urlencoded(req, res, next) {
- if (req._body) return next();
- req.body = req.body || {};
-
- if (!utils.hasBody(req)) return next();
-
- // check Content-Type
- if ('application/x-www-form-urlencoded' != utils.mime(req)) return next();
-
- // flag as parsed
- req._body = true;
-
- // parse
- getBody(req, {
- limit: options.limit || '1mb',
- length: req.headers['content-length'],
- encoding: 'utf8'
- }, function (err, buf) {
- if (err) return next(err);
-
- if (verify) {
- try {
- verify(req, res, buf)
- } catch (err) {
- if (!err.status) err.status = 403;
- return next(err);
- }
- }
-
- try {
- req.body = buf.length
- ? qs.parse(buf)
- : {};
- } catch (err){
- err.body = buf;
- return next(err);
- }
- next();
- })
- }
-};
View
@@ -17,35 +17,6 @@ var http = require('http')
, signature = require('cookie-signature');
/**
- * Return `true` if the request has a body, otherwise return `false`.
- *
- * @param {IncomingMessage} req
- * @return {Boolean}
- * @api private
- */
-
-exports.hasBody = function(req) {
- var encoding = 'transfer-encoding' in req.headers;
- var length = 'content-length' in req.headers && req.headers['content-length'] !== '0';
- return encoding || length;
-};
-
-/**
- * Extract the mime type from the given request's
- * _Content-Type_ header.
- *
- * @param {IncomingMessage} req
- * @return {String}
- * @api private
- */
-
-exports.mime = function(req) {
- var str = req.headers['content-type'] || ''
- , i = str.indexOf(';');
- return ~i ? str.slice(0, i) : str;
-};
-
-/**
* Generate an `Error` from the given status `code`
* and optional `msg`.
*
View
@@ -23,14 +23,11 @@
"uid2": "0.0.3",
"debug": ">= 0.7.3 < 1",
"methods": "0.1.0",
- "raw-body": "1.1.2",
"negotiator": "0.3.0"
},
"devDependencies": {
"should": ">= 2.0.2 < 3",
- "mocha": ">= 1.13.0 < 2",
- "jade": ">= 0.35.0 < 1",
- "dox": ">= 0.4.4 < 1"
+ "mocha": ">= 1.13.0 < 2"
},
"licenses": [
{
@@ -40,7 +37,7 @@
],
"main": "index",
"engines": {
- "node": ">= 0.8.0"
+ "node": ">= 0.10.0"
},
"scripts": {
"test": "make"
Oops, something went wrong.

0 comments on commit 5c5e81f

Please sign in to comment.