Skip to content

Commit

Permalink
Disable keep-alive on HTTP and HTTPS global agents on all Node versio…
Browse files Browse the repository at this point in the history
…ns when enabled.
  • Loading branch information
moll committed Aug 24, 2024
1 parent 3455264 commit 7bc6320
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var slice = Function.call.bind(Array.prototype.slice)
var normalizeConnectArgs = Net._normalizeConnectArgs || Net._normalizeArgs
var createRequestAndResponse = Http._connectionListener
var NODE_0_10 = Semver.satisfies(process.version, ">= 0.10 < 0.11")
var NODE_GTE_19 = Semver.satisfies(process.version, ">= 19")
module.exports = Mitm

function Mitm() {
Expand Down Expand Up @@ -62,11 +61,12 @@ Mitm.prototype.enable = function() {
this.stubs.stub(Http.globalAgent, "maxSockets", Infinity)
this.stubs.stub(Https.globalAgent, "maxSockets", Infinity)
}
else if (NODE_GTE_19) {
// Note v19 enables keep-alive for both the Http and Https globalAgents.

// Note v19 enables keep-alive for both the Http and Https globalAgents.
if (Http.globalAgent.keepAlive)
this.stubs.stub(Http.globalAgent, "keepAlive", false)
if (Https.globalAgent.keepAlive)
this.stubs.stub(Https.globalAgent, "keepAlive", false)
}

// ClientRequest.prototype.onSocket is called synchronously from
// ClientRequest's constructor and is a convenient place to hook into new
Expand Down

0 comments on commit 7bc6320

Please sign in to comment.