Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mitm-papandreou

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mitm-papandreou - npm Package Compare versions

Comparing version 1.3.3-patch4 to 1.3.3-patch5

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## Unreleased
- Adds Node v8.12, Node v9 and Node v10 support.
Thanks to [Andreas Lind](https://github.com/papandreou) for help in debugging! Also thanks to him for providing [mitm-papandreou](https://www.npmjs.com/package/mitm-papandreou) while Mitm.js-proper incorporated his fixes.
## 1.3.3 (Sep 16, 2017)

@@ -2,0 +6,0 @@ - Fixes `getAsyncId` error on Node v8 when using an `Http.Agent` with the `keepAlive` option.

58

index.js

@@ -12,5 +12,7 @@ var _ = require("underscore")

var Stubs = require("./lib/stubs")
var Semver = require("semver")
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")
module.exports = Mitm

@@ -35,20 +37,9 @@

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
if (NODE_GTE_9_6_0) {
var _httpServer = require('_http_server')
var _httpIncoming = require('_http_incoming')
var kIncomingMessage = require('_http_common').kIncomingMessage
TlsSocket.prototype[kIncomingMessage] =
Socket.prototype[kIncomingMessage] =
Mitm.prototype[kIncomingMessage] =
_httpIncoming.IncomingMessage
Mitm.prototype[_httpServer.kServerResponse] = _httpServer.ServerResponse
if (Semver.satisfies(process.version, "^8.12 || >= 9.6")) {
var IncomingMessage = require("_http_incoming").IncomingMessage
var ServerResponse = require("_http_server").ServerResponse
var incomingMessageKey = require("_http_common").kIncomingMessage
var serverResponseKey = require("_http_server").kServerResponse
Mitm.prototype[serverResponseKey] = ServerResponse
Mitm.prototype[incomingMessageKey] = IncomingMessage
}

@@ -94,8 +85,27 @@

var sockets = InternalSocket.pair()
var client = new Socket(_.defaults({handle: sockets[0]}, opts))
// Don't set client.connecting to false because there's nothing setting it
// back to false later. Originally that was done in Socket.prototype.connect
// and its afterConnect handler, but we're not calling that.
var client = new Socket(_.defaults({
handle: sockets[0],
// Node v10 expects readable and writable to be set at Socket creation time.
readable: true,
writable: true
}, opts))
this.emit("connect", client, opts)
if (client.bypassed) return orig.call(this, opts, done)
var server = client.server = new Socket({handle: sockets[1]})
// Don't use just "server" because socket.server is used in Node v8.12 and
// Node v9.6 and later for modifying the HTTP server response and parser
// classes. If unset, it's set to the used HTTP server (Mitm instance in our
// case) in _http_server.js.
// See also: https://github.com/nodejs/node/issues/13435.
var server = client.serverSocket = new Socket({
handle: sockets[1],
readable: true,
writable: true
})

@@ -125,3 +135,3 @@ this.emit("connection", server, opts)

var client = this.connect(orig, Socket, opts, done)
if (client.server == null) return client
if (client.serverSocket == null) return client
if (done) client.once("connect", done)

@@ -137,3 +147,3 @@

var client = this.connect(orig, TlsSocket, opts, done)
if (client.server == null) return client
if (client.serverSocket == null) return client
if (done) client.once("secureConnect", done)

@@ -147,3 +157,3 @@

Mitm.prototype.request = function request(socket) {
if (!socket.server) return socket
if (!socket.serverSocket) return socket

@@ -160,3 +170,3 @@ // Node >= v0.10.24 < v0.11 will crash with: «Assertion failed:

createRequestAndResponse.call(self, socket.server)
createRequestAndResponse.call(self, socket.serverSocket)
return socket

@@ -163,0 +173,0 @@ }

var DuplexStream = require("stream").Duplex
var Semver = require("semver")
var uniqueId = 0
var NO_ERROR = 0
exports = module.exports = InternalSocket
exports.pair = pair
var NODE_0_10 = !!process.version.match(/^v0\.10\./)
var NODE_0_10 = Semver.satisfies(process.version, ">= 0.10 < 0.11")
var NODE_10_AND_LATER = Semver.satisfies(process.version, ">= 10")
if (!NODE_0_10) var Uv = process.binding("uv")

@@ -36,11 +39,9 @@

// ReadStart may be called multiple times.
// Node v0.11's ReadableStream.prototype.resume and
// ReadableStream.prototype.pause return self. InternalSocket's API states that
// they should return error codes instead.
//
// Node v0.11's ReadableStream.prototype.resume and ReadableStream.prototype.pause return
// self. InternalSocket's API states that they should return error codes
// instead.
//
// Node v0.11.13 called ReadableStream.prototype.read(0) synchronously, but
// v0.11.14 does it in the next tick. For easier sync use, call it here.
InternalSocket.prototype.readStart = function() { this.resume(); this.read(0) }
InternalSocket.prototype.readStart = function() { this.resume() }
InternalSocket.prototype.readStop = function() { this.pause() }

@@ -61,5 +62,13 @@ InternalSocket.prototype.close = InternalSocket.prototype.end

// Node v10 requires writev to be set on the handler because, while
// WritableStream expects _writev, internal/stream_base_commons.js calls
// req.handle.writev directly. It's given a flat array of data+type pairs.
if (NODE_10_AND_LATER) InternalSocket.prototype.writev = function(_req, data) {
for (var i = 0; i < data.length; ++i) this._write(data[i], data[++i], noop)
return NO_ERROR
}
// NOTE: Node v0.10 expects InternalSocket to return write request objects with
// a "oncomplete" and "cb" property. Node v0.11 expects it return an error
// instead.
// instead. Node v10 expects it to return an error code.

@@ -69,6 +78,9 @@ // InternalSocket.prototype.writeBinaryString was introduced in Node v0.11.14.

this.write(data, "binary")
if (NODE_10_AND_LATER) return NO_ERROR
}
// InternalSocket.prototype.writeLatin1String was introduced in Node v6.4.
InternalSocket.prototype.writeLatin1String = function(_req, data) {
this.write(data, "latin1")
if (NODE_10_AND_LATER) return NO_ERROR
}

@@ -80,2 +92,3 @@

if (NODE_0_10) return {}
else if (NODE_10_AND_LATER) return NO_ERROR
}

@@ -87,2 +100,3 @@

if (NODE_0_10) return {}
else if (NODE_10_AND_LATER) return NO_ERROR
}

@@ -94,2 +108,3 @@

if (NODE_0_10) return {}
else if (NODE_10_AND_LATER) return NO_ERROR
}

@@ -101,2 +116,3 @@

if (NODE_0_10) return {}
else if (NODE_10_AND_LATER) return NO_ERROR
}

@@ -103,0 +119,0 @@

{
"name": "mitm-papandreou",
"version": "1.3.3-patch4",
"version": "1.3.3-patch5",
"description": "Intercept and mock outgoing network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Useful when testing code that hits remote servers.",

@@ -40,10 +40,10 @@ "keywords": [

"dependencies": {
"underscore": ">= 1.1.6 < 1.6"
"underscore": ">= 1.1.6 < 1.6",
"semver": ">= 5 < 6"
},
"devDependencies": {
"mocha": ">= 1.12.0 < 1.19",
"mocha": ">= 1.12.0 < 3",
"must": ">= 0.13 < 0.14",
"sinon": ">= 1.9 < 2",
"semver": ">= 5 < 6"
"sinon": ">= 1.9 < 2"
},

@@ -50,0 +50,0 @@

@@ -19,4 +19,3 @@ Mitm.js

Mitm.js should work both on the stable Node **v0.10.24** and up and **v0.11.11**
and up and has **automated tests** to ensure it will stay that way.
Mitm.js works on all Node versions: ancient **v0.10**, **v0.11** and **v0.12** versions, previous and current LTS versions like **v4**, **v6** and **v8** and fresh **v10** and beyond. For all it has **automated tests** to ensure it will stay that way.

@@ -23,0 +22,0 @@ I've developed Mitm.js on a need-to basis for testing [Monday

@@ -358,2 +358,13 @@ var _ = require("underscore")

})
// Bug report from Io.js v3 days:
// https://github.com/moll/node-mitm/issues/26
describe(".prototype.destroy", function() {
it("must emit end when destroyed on server", function(done) {
var server; this.mitm.on("connection", function(s) { server = s })
var client = Net.connect({host: "foo"})
server.destroy()
client.on("end", done)
})
})
})

@@ -360,0 +371,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc