Skip to content

Commit

Permalink
Wire up internals for node.js 9.6.0+ compatibility
Browse files Browse the repository at this point in the history
Fixes moll#48
  • Loading branch information
papandreou committed Feb 24, 2018
1 parent bfbd620 commit 02a543f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ Mitm.prototype.addListener = EventEmitter.prototype.addListener
Mitm.prototype.removeListener = EventEmitter.prototype.removeListener
Mitm.prototype.emit = EventEmitter.prototype.emit

var NODE_0_10 = !!process.version.match(/^v0\.10\./)
var versionDigits = process.version.replace(/^v/, '').split('.').map(function(str) {
return parseInt(str, 10);
})
var NODE_0_10 = versionDigits[0] === 0 && versionDigits[1] === 10
var NODE_GTE_9_6_0 =
(versionDigits[0] === 9 && versionDigits[1] >= 6) || versionDigits[0] > 9

Mitm.prototype.enable = function() {
// Connect is called synchronously.
Expand Down Expand Up @@ -77,6 +82,17 @@ Mitm.prototype.connect = function connect(orig, Socket, opts, done) {
if (client.bypassed) return orig.call(this, opts, done)

var server = client.server = new Socket({handle: sockets[1]})

if (NODE_GTE_9_6_0) {
var _httpServer = require('_http_server')
var _httpIncoming = require('_http_incoming')
var kIncomingMessage = require('_http_common').kIncomingMessage
server[kIncomingMessage] = this[kIncomingMessage] =
_httpIncoming.IncomingMessage

this[_httpServer.kServerResponse] = _httpServer.ServerResponse
}

this.emit("connection", server, opts)

// Ensure connect is emitted in next ticks, otherwise it would be impossible
Expand Down

0 comments on commit 02a543f

Please sign in to comment.