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

Allow calling next on finish #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ function serveStatic (root, options) {
if (setHeaders && typeof setHeaders !== 'function') {
throw new TypeError('option setHeaders must be function')
}

var callNextOnFinish = opts.callNextOnFinish === true;

// setup options for send
opts.maxage = opts.maxage || opts.maxAge || 0
Expand Down Expand Up @@ -120,6 +122,17 @@ function serveStatic (root, options) {

next()
})

if(callNextOnFinish){
res.once('finish', function () {
next();
})
res.once('close', function() {
if(!res.writableEnded){
next(new Error('Did not finish sending data (client my have aborted mid request)'))
}
})
}

// pipe
stream.pipe(res)
Expand Down