Permalink
Browse files

more consistent handlers

  • Loading branch information...
1 parent d11ae8c commit d359c4d8d596fc3f61c4bcada8cd8f7c2aac63aa @chjj chjj committed Oct 17, 2011
Showing with 7 additions and 4 deletions.
  1. +3 −3 lib/encoded.js
  2. +4 −1 lib/json.js
View
@@ -36,7 +36,7 @@ Parser.prototype.write = function(data) {
if (!this.writable) return;
try {
- this._write(data);
+ this._parse(data);
this.written += data.length;
this.emit('data', data.length);
} catch(e) {
@@ -60,7 +60,7 @@ Parser.prototype.end = function(data) {
this.emit('end');
};
-Parser.prototype._write = function(data) {
+Parser.prototype._parse = function(data) {
var i = 0
, k = 0
, l = data.length
@@ -165,7 +165,6 @@ Parser.handle = function(req, res, next, options) {
});
parser.on('end', function() {
- req.body = data;
next();
});
@@ -183,6 +182,7 @@ Parser.handle = function(req, res, next, options) {
});
}
+ req.body = data;
req.pipe(parser);
};
View
@@ -499,7 +499,7 @@ exports.handle = function(req, res, next, options) {
, limit = options.jsonLimit || options.limit;
parser.on('error', function(err) {
- req.socket.destroy();
+ req.destroy();
next(err);
});
@@ -517,4 +517,7 @@ exports.handle = function(req, res, next, options) {
}
});
}
+
+ req.body = {};
+ req.pipe(parser);
};

0 comments on commit d359c4d

Please sign in to comment.