Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparation for the deprecation of http.ServerResponse.finished #135

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})