req: Fix bug where it would call requestEnded when request was closed. This behavior is normal during the middle of a request
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
cffca53eb6
commit
4820347cfb
4 changed files with 31 additions and 10 deletions
|
@ -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)
|
||||
})
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue