Permalink
Browse files

use utils.error(code) directly

  • Loading branch information...
1 parent c8fa49d commit 11851b08783207d86c0c77fb0de1af4b360e6f92 @tj tj committed Nov 17, 2011
Showing with 10 additions and 16 deletions.
  1. +1 −1 lib/middleware/basicAuth.js
  2. +1 −1 lib/middleware/csrf.js
  3. +3 −3 lib/middleware/directory.js
  4. +1 −1 lib/middleware/limit.js
  5. +4 −4 lib/middleware/static.js
  6. +0 −6 lib/proto.js
View
2 lib/middleware/basicAuth.js
@@ -67,7 +67,7 @@ module.exports = function basicAuth(callback, realm) {
, scheme = parts[0]
, credentials = new Buffer(parts[1], 'base64').toString().split(':');
- if ('Basic' != scheme) return next(400);
+ if ('Basic' != scheme) return next(utils.error(400));
// async
if (callback.length >= 3) {
View
2 lib/middleware/csrf.js
@@ -83,7 +83,7 @@ module.exports = function csrf(options) {
var val = value(req);
// check
- if (val != token) return next(403);
+ if (val != token) return next(utils.error(403));
next();
}
View
6 lib/middleware/directory.js
@@ -63,10 +63,10 @@ exports = module.exports = function directory(root, options){
, showUp = path != root && path != root + '/';
// null byte(s), bad request
- if (~path.indexOf('\0')) return next(400);
+ if (~path.indexOf('\0')) return next(utils.error(400));
// malicious path, forbidden
- if (0 != path.indexOf(root)) return next(403);
+ if (0 != path.indexOf(root)) return next(utils.error(403));
// check if we have a directory
fs.stat(path, function(err, stat){
@@ -92,7 +92,7 @@ exports = module.exports = function directory(root, options){
}
// not acceptable
- next(406);
+ next(utils.error(406));
});
});
};
View
2 lib/middleware/limit.js
@@ -41,7 +41,7 @@ module.exports = function limit(bytes){
req._limit = true;
// limit by content-length
- if (len && len > bytes) return next(413);
+ if (len && len > bytes) return next(utils.error(413));
// limit
req.on('data', function(chunk){
View
8 lib/middleware/static.js
@@ -104,10 +104,10 @@ var send = exports.send = function(req, res, next, options){
, type;
// null byte(s)
- if (~path.indexOf('\0')) return next(400);
+ if (~path.indexOf('\0')) return next(utils.error(400));
// when root is not given, consider .. malicious
- if (!root && ~path.indexOf('..')) return next(403);
+ if (!root && ~path.indexOf('..')) return next(utils.error(403));
// index.html support
if ('/' == path[path.length - 1]) path += 'index.html';
@@ -116,7 +116,7 @@ var send = exports.send = function(req, res, next, options){
path = normalize(join(root, path));
// malicious path
- if (root && 0 != path.indexOf(root)) return next(403);
+ if (root && 0 != path.indexOf(root)) return next(utils.error(403));
// "hidden" file
if (!hidden && '.' == basename(path)[0]) return next();
@@ -181,7 +181,7 @@ var send = exports.send = function(req, res, next, options){
+ stat.size);
// invalid range
} else {
- return next(416);
+ return next(utils.error(416));
}
}
View
6 lib/proto.js
@@ -116,12 +116,6 @@ app.handle = function(req, res, out) {
req.originalUrl = req.originalUrl || req.url;
removed = '';
- // next(status) support
- if ('number' == typeof err) {
- status = err;
- err = utils.error(err);
- }
-
// next callback
layer = stack[index++];

0 comments on commit 11851b0

Please sign in to comment.