Permalink
Browse files

emit end event if ended when manualy triggering unbuffer

  • Loading branch information...
1 parent 47bbb17 commit b1c9bf0711af1849633f799e4c2d90efd5c32600 @tellnes tellnes committed Jan 6, 2013
Showing with 23 additions and 0 deletions.
  1. +10 −0 examples/simple/simple.js
  2. +1 −0 lib/buffered-stream.js
  3. +12 −0 test/simple-test.js
@@ -45,6 +45,16 @@ router.get('/custom_redirect', function() {
this.res.redirect('/foo', 301);
});
+router.get('/async', function () {
+ var self = this;
+ process.nextTick(function () {
+ self.req.on('end', function () {
+ self.res.end();
+ })
+ self.req.buffer = false;
+ });
+});
+
server.listen(9090);
console.log('union with director running on 9090');
@@ -47,6 +47,7 @@ Object.defineProperty(BufferedStream.prototype, 'buffer', {
if (!value && this.chunks) {
var self = this;
this.chunks.forEach(function (c) { self.emit('data', c) });
+ if (this.ended) this.emit('end');
this.size = 0;
delete this.chunks;
}
View
@@ -72,6 +72,18 @@ vows.describe('union/simple').addBatch({
assert.equal(res.statusCode, 301);
assert.equal(res.headers.location, "http://localhost:9090/foo");
}
+ },
+ "a GET request to `/async`": {
+ topic: function() {
+ request.get({
+ url: 'http://localhost:9090/async',
+ timeout: 500
+ }, this.callback);
+ },
+ "it should not timeout": function (err, res, body) {
+ assert.ifError(err);
+ assert.equal(res.statusCode, 200);
+ }
}
}
}

0 comments on commit b1c9bf0

Please sign in to comment.