Skip to content

Commit

Permalink
Use boolean to enable connection tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Jan 17, 2022
1 parent 80aef3f commit e9e4bf6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function fastify (options) {
caseSensitive: options.caseSensitive,
buildPrettyMeta: defaultBuildPrettyMeta,
},
trackConnections: false,
keepAliveConnections
})

Expand Down
14 changes: 8 additions & 6 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const {
} = require('./symbols.js')

function buildRouting (options) {
const {keepAliveConnections} = options
const { keepAliveConnections, trackConnections } = options
const router = FindMyWay(options.config)

let avvio
Expand Down Expand Up @@ -345,11 +345,13 @@ function buildRouting (options) {
}
}

const connHeader = String.prototype.toLowerCase.call(req.headers.connection || '')
if (connHeader === 'keep-alive') {
if (keepAliveConnections.has(req.socket) === false) {
keepAliveConnections.add(req.socket)
req.socket.on('close', removeTrackedSocket.bind({ keepAliveConnections, socket: req.socket }))
if (trackConnections === true) {
const connHeader = String.prototype.toLowerCase.call(req.headers.connection || '')
if (connHeader === 'keep-alive') {
if (keepAliveConnections.has(req.socket) === false) {
keepAliveConnections.add(req.socket)
req.socket.on('close', removeTrackedSocket.bind({ keepAliveConnections, socket: req.socket }))
}
}
}

Expand Down

0 comments on commit e9e4bf6

Please sign in to comment.