Skip to content

Commit

Permalink
Merge branch "features/latin1".
Browse files Browse the repository at this point in the history
  • Loading branch information
moll committed Aug 17, 2016
2 parents 2ee831e + 3034d13 commit 568172c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ node_js:
- "0.12"
- "4"
- "5"
- "6"
- "6.0"
- "6.4"
- "iojs"
- "iojs-v2.4.0"
- "iojs-v3.2.0"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased
- Adds compatibility with Node v6.4.
Thanks to [Andreas Lind](https://github.com/papandreou)!

## 1.2.1 (Mar 30, 2016)
- Fixes writing to sockets returned by Mitm by postponing writing until the next
tick. Brings it in line with Node's behavior.
Expand Down
4 changes: 4 additions & 0 deletions lib/internal_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ InternalSocket.prototype.writeBinaryString = function(req, data) {
this.write(data, "binary")
}

InternalSocket.prototype.writeLatin1String = function(req, data) {
this.write(data, "latin1")
}

InternalSocket.prototype.writeBuffer = function(req, data) {
this.write(NODE_0_10 ? req : data)
if (NODE_0_10) return {}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"devDependencies": {
"mocha": ">= 1.12.0 < 1.19",
"must": ">= 0.13 < 0.14",
"sinon": ">= 1.9 < 2"
"sinon": ">= 1.9 < 2",
"semver": ">= 5 < 6"
},

"engines": {"node": ">= 0.10.24"}
Expand Down
17 changes: 15 additions & 2 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ var Net = require("net")
var Tls = require("tls")
var Http = require("http")
var Https = require("https")
var Semver = require("semver")
var IncomingMessage = Http.IncomingMessage
var ServerResponse = Http.ServerResponse
var ClientRequest = Http.ClientRequest
var EventEmitter = require("events").EventEmitter
var Mitm = require("..")
var NODE_0_10 = !!process.version.match(/^v0\.10\./)
var NODE_0_10 = Semver.satisfies(process.version, ">= 0.10 < 0.11")

describe("Mitm", function() {
beforeEach(function() { Mitm.passthrough = false })
Expand Down Expand Up @@ -233,7 +234,6 @@ describe("Mitm", function() {
ticked = true
})


// Writing binary strings was introduced in Node v0.11.14.
// The test still passes for Node v0.10 and newer v0.11s, so let it be.
it("must write to server from client given binary", function(done) {
Expand All @@ -246,6 +246,19 @@ describe("Mitm", function() {
process.nextTick(done)
})

// Writing latin1 strings was introduced in v6.4.
// https://github.com/nodejs/node/commit/28071a130e2137bd14d0762a25f0ad83b7a28259
if (Semver.satisfies(process.version, ">= 6.4"))
it("must write to server from client given latin1", function(done) {
var server; this.mitm.on("connection", function(s) { server = s })
var client = Net.connect({host: "foo"})
client.write("Hello", "latin1")

server.setEncoding("latin1")
process.nextTick(function() { server.read().must.equal("Hello") })
process.nextTick(done)
})

it("must write to server from client given a buffer", function(done) {
var server; this.mitm.on("connection", function(s) { server = s })
var client = Net.connect({host: "foo"})
Expand Down

0 comments on commit 568172c

Please sign in to comment.