diff --git a/HISTORY.md b/HISTORY.md index 5d1e1c9..bbc93e4 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Fix `isFinished(req)` when data buffered + 2.2.0 / 2014-12-22 ================== diff --git a/index.js b/index.js index f68161c..2402c76 100644 --- a/index.js +++ b/index.js @@ -67,7 +67,7 @@ function isFinished(msg) { if (typeof msg.complete === 'boolean') { // IncomingMessage - return Boolean(!socket || msg.complete || !socket.readable) + return Boolean(!socket || !socket.readable || (msg.complete && !msg.readable)) } // don't know diff --git a/test/test.js b/test/test.js index 72aa1d9..dac2685 100644 --- a/test/test.js +++ b/test/test.js @@ -551,6 +551,24 @@ describe('isFinished(req)', function () { sendget(server) }) + describe('when request data buffered', function () { + it('should be false before request finishes', function (done) { + var server = http.createServer(function (req, res) { + assert.ok(!onFinished.isFinished(req)) + + req.pause() + setTimeout(function () { + assert.ok(!onFinished.isFinished(req)) + req.resume() + res.end() + done() + }, 10) + }) + + sendget(server) + }) + }) + describe('when request errors', function () { it('should return true', function (done) { var server = http.createServer(function (req, res) {