From c3b7447024226e511d6427c6fcdd01f8b0e223c3 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Sun, 10 Oct 2021 21:32:15 +0000 Subject: [PATCH] requestEnd: Fix detection on when response is finished --- flaska.mjs | 2 +- test/flaska.out.test.mjs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/flaska.mjs b/flaska.mjs index bf337d9..3e8731a 100644 --- a/flaska.mjs +++ b/flaska.mjs @@ -467,7 +467,7 @@ export class Flaska { if (err) { this._onerror(err, ctx) } - if (ctx.req.complete) { + if (ctx.res.writableEnded) { return } diff --git a/test/flaska.out.test.mjs b/test/flaska.out.test.mjs index 9bc9475..baeb8c7 100644 --- a/test/flaska.out.test.mjs +++ b/test/flaska.out.test.mjs @@ -198,6 +198,17 @@ t.describe('#requestEnd()', function() { flaska.requestEnd(null, ctx) }) + t.test('should return immediately if req is finished', function() { + let onFinish = function() { + throw new Error('should not be called') + } + const ctx = createCtx({ }, onFinish) + ctx.res.writableEnded = true + + let flaska = new Flaska({}, fakerHttp, fakeStream) + flaska.requestEnd(null, ctx) + }) + const emptyStatuses = [204, 205, 304] emptyStatuses.forEach(function(status) {