requestEnd: Fix detection on when response is finished

This commit is contained in:
Jonatan Nilsson 2021-10-10 21:32:15 +00:00
parent 6fe5a7272d
commit c3b7447024
2 changed files with 12 additions and 1 deletions

View file

@ -467,7 +467,7 @@ export class Flaska {
if (err) { if (err) {
this._onerror(err, ctx) this._onerror(err, ctx)
} }
if (ctx.req.complete) { if (ctx.res.writableEnded) {
return return
} }

View file

@ -198,6 +198,17 @@ t.describe('#requestEnd()', function() {
flaska.requestEnd(null, ctx) 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] const emptyStatuses = [204, 205, 304]
emptyStatuses.forEach(function(status) { emptyStatuses.forEach(function(status) {