From bd0a273efefd3d47b2be2e79b84408248b7f9448 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Wed, 22 Apr 2015 21:24:51 -0400 Subject: [PATCH] Fix isFinished(req) when data buffered --- HISTORY.md | 5 +++++ index.js | 2 +- test/test.js | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) 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) {