Skip to content

Commit

Permalink
Use res.headersSent when available
Browse files Browse the repository at this point in the history
closes #15
  • Loading branch information
mcollina authored and dougwilson committed Sep 22, 2017
1 parent ed4c24d commit e249491
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
@@ -1,3 +1,8 @@
unreleased
==========

* Use `res.headersSent` when available

1.0.6 / 2017-09-22
==================

Expand Down
18 changes: 16 additions & 2 deletions index.js
Expand Up @@ -89,7 +89,7 @@ function finalhandler (req, res, options) {
var status

// ignore 404 on in-flight response
if (!err && res._header) {
if (!err && headersSent(res)) {
debug('cannot 404 after headers sent')
return
}
Expand Down Expand Up @@ -125,7 +125,7 @@ function finalhandler (req, res, options) {
}

// cannot actually respond
if (res._header) {
if (headersSent(res)) {
debug('cannot %d after headers sent', status)
req.socket.destroy()
return
Expand Down Expand Up @@ -227,6 +227,20 @@ function getResponseStatusCode (res) {
return status
}

/**
* Determine if the response headers have been sent.
*
* @param {object} res
* @returns {boolean}
* @private
*/

function headersSent (res) {
return typeof res.headersSent !== 'boolean'
? Boolean(res._header)
: res.headersSent
}

/**
* Send response.
*
Expand Down

0 comments on commit e249491

Please sign in to comment.