diff --git a/flaska.mjs b/flaska.mjs index 1d39093..7edc929 100644 --- a/flaska.mjs +++ b/flaska.mjs @@ -833,11 +833,6 @@ ctx.state.nonce = nonce; this._onreserror(err, ctx) }) - req.on('close', () => { - ctx.closed = true - this.requestEnded(ctx) - }) - res.on('finish', () => { this.requestEnded(ctx) }) diff --git a/package.json b/package.json index 8f00ba4..43c48c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flaska", - "version": "1.2.2", + "version": "1.2.3", "description": "Flaska is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.", "main": "flaska.mjs", "scripts": { diff --git a/test/flaska.in.test.mjs b/test/flaska.in.test.mjs index 30338cd..8283f83 100644 --- a/test/flaska.in.test.mjs +++ b/test/flaska.in.test.mjs @@ -22,7 +22,7 @@ t.describe('#requestStart()', function() { flaska.requestEnd = function(err, ctx) { try { assert.ok(err) - assert.strictEqual(assertReq.on.callCount, 2) + assert.strictEqual(assertReq.on.callCount, 1) assert.strictEqual(assertRes.on.callCount, 2) @@ -46,9 +46,6 @@ t.describe('#requestStart()', function() { assert.strictEqual(onReqError.callCount, 1) assert.strictEqual(onReqError.firstCall[0], assertErrorOne) assert.strictEqual(onReqError.firstCall[1], ctx) - - assert.strictEqual(assertReq.on.secondCall[0], 'close') - assert.strictEqual(typeof(assertReq.on.secondCall[1]), 'function') // Test abort and close diff --git a/test/http.test.mjs b/test/http.test.mjs index d95e8ef..168e31c 100644 --- a/test/http.test.mjs +++ b/test/http.test.mjs @@ -24,6 +24,11 @@ let reqBody = null let file = null let uploaded = [] +flaska.after(function(ctx) { + if (ctx.aborted) return + ctx.log.info(ctx.status) +}) + flaska.get('/', function(ctx) { ctx.body = { status: true } }) @@ -31,6 +36,12 @@ flaska.post('/json', JsonHandler(), function(ctx) { ctx.body = { success: true } reqBody = ctx.req.body }) +flaska.post('/json/slow', JsonHandler(), async function(ctx) { + await setTimeout(300) + ctx.body = { success: true } + ctx.status = 201 + reqBody = ctx.req.body +}) flaska.get('/timeout', function(ctx) { return new Promise(function() {}) }) @@ -79,6 +90,9 @@ t.describe('/', function() { }) t.describe('/json', function() { + t.beforeEach(function() { + log.info.reset() + }) t.test('should return success and store body', async function() { const assertBody = { a: '' } for (let i = 0; i < 1010; i++) { @@ -88,6 +102,21 @@ t.describe('/json', function() { let body = await client.post('/json', assertBody) assert.deepEqual(body, { success: true }) assert.deepStrictEqual(reqBody, assertBody) + assert.strictEqual(log.info.callCount, 1) + assert.strictEqual(log.info.firstCall[0], 200) + }) + + t.test('should return and log correctly', async function() { + const assertBody = { a: '' } + for (let i = 0; i < 1010; i++) { + assertBody.a += 'aaaaaaaaaa' + } + reqBody = null + let body = await client.post('/json/slow', assertBody) + assert.deepEqual(body, { success: true }) + assert.deepStrictEqual(reqBody, assertBody) + assert.strictEqual(log.info.callCount, 1) + assert.strictEqual(log.info.firstCall[0], 201) }) t.test('should fail if body is too big', async function() {