Skip to content

Commit

Permalink
added support for http.ServerResponse.writableEnded (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaow-de committed Mar 21, 2022
1 parent 0e4096a commit e8963a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function middie (complete) {

req.url = req.originalUrl

if (res.finished === true) {
if (res.finished === true || res.writableEnded === true) {
that.req = null
that.res = null
that.context = null
Expand Down
24 changes: 23 additions & 1 deletion test/engine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ test('should match the same slashed path', t => {
instance.run(req, res)
})

test('if the function calls res.end the iterator should stop', t => {
test('if the function calls res.end the iterator should stop / 1 (with deprecated finished flag)', t => {
t.plan(1)

const instance = middie(function () {
Expand Down Expand Up @@ -495,3 +495,25 @@ test('if the function calls res.end the iterator should stop', t => {

instance.run(req, res)
})

test('if the function calls res.end the iterator should stop / 2', t => {
t.plan(0)

const instance = middie(function () {
t.fail('we should not be here')
})
const req = new http.IncomingMessage(null)
req.url = '/test'
const res = new http.ServerResponse(req)

instance
.use(function (req, res, next) {
res.end('bye')
next()
})
.use(function (req, res, next) {
t.fail('we should not be here')
})

instance.run(req, res)
})

0 comments on commit e8963a0

Please sign in to comment.