Skip to content

Commit

Permalink
fix(refactor): remove ServerResponse.headersSent support check (#77)
Browse files Browse the repository at this point in the history
`http.ServerResponse.headersSent` was added in v0.9.3. `http2.Http2ServerResponse.headersSent` was added in v8.4.0
  • Loading branch information
Phillip9587 authored Jan 10, 2025
1 parent 401ec84 commit c70bf84
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
unreleased
==================

* remove `ServerResponse.headersSent` support check
* remove unnecessary devDependency `safe-buffer`
* remove `unpipe` package and use native `unpipe()` method
* remove unnecessary devDependency `readable-stream`
Expand Down
18 changes: 2 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function finalhandler (req, res, options) {
var status

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

// cannot actually respond
if (headersSent(res)) {
if (res.headersSent) {
debug('cannot %d after headers sent', status)
if (req.socket) {
req.socket.destroy()
Expand Down Expand Up @@ -245,20 +245,6 @@ 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 c70bf84

Please sign in to comment.