1
0
mirror of synced 2025-12-21 02:46:50 -05:00
Files
docs/middleware/halt-on-dropped-connection.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

19 lines
641 B
JavaScript

export function isConnectionDropped(req, res) {
// Have the flags been set for:
// - a global request timeout (via the express-timeout-handler middleware)?
// - an aborted request connection (via Node.js core's HTTP IncomingMessage)?
return Boolean(res.globalTimeout || req.aborted)
}
export function haltOnDroppedConnection(req, res, next) {
// Only proceed if the flag has not been set for the express-timeout-handler middleware
if (!isConnectionDropped(req, res)) {
return next()
}
}
// Export this logic, too
haltOnDroppedConnection.isConnectionDropped = isConnectionDropped
export default haltOnDroppedConnection