Skip to content

Commit

Permalink
Merge 0c38e8d into 94feedb
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasimensah committed Jul 20, 2020
2 parents 94feedb + 0c38e8d commit 6693255
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
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', ()=>{
next();
})
res.once('close', ()=>{
if(!res.writableEnded){
next(new Error('Did not finish sending data (client my have aborted mid request)'))
}
})
}

// pipe
stream.pipe(res)
Expand Down

0 comments on commit 6693255

Please sign in to comment.