From ecf1aaddf2e579093edee9854134a640d6b02cd2 Mon Sep 17 00:00:00 2001 From: Craig Condon Date: Sat, 3 Nov 2012 13:22:30 -0500 Subject: [PATCH 1/4] require dep bufferjs < 2.0.0 2.0 changes break filternet --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0f5112b..3aef50c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "homepage": "https://github.com/axiak/filternet", "bugs": "https://github.com/axiak/filternet/issues", "dependencies": { - "bufferjs": ">= 1.0.0" + "bufferjs": "<2.0.0" }, "main": "index", "license": "BSD", From 63a19c5597af2ebaf5b1a1fd312342dd6d7d659c Mon Sep 17 00:00:00 2001 From: Craig Condon Date: Sat, 3 Nov 2012 23:23:30 -0500 Subject: [PATCH 2/4] Update for n 0.8.14 --- lib/proxy.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/proxy.js b/lib/proxy.js index 7aaf018..965b8d3 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -9,7 +9,6 @@ var http = require('http') , zlib = require('zlib') , sniparse = require('./sniparse'); -require('bufferjs/concat'); require('bufferjs/add-chunk'); require('./regexp-escape'); @@ -137,7 +136,7 @@ module.exports.createProxyServer = function (opts) { proxyResponse.headers['content-type'].toLowerCase().indexOf("html") != -1); var writeResponse = function (shouldBuffer) { - var buffer = undefined, bufferLength = 0; + var buffer = undefined, buffers = [], bufferLength = 0; if (shouldBuffer) { bufferLength = ~~(proxyResponse.headers['content-length'] || 0); delete proxyResponse.headers['content-length']; @@ -151,7 +150,8 @@ module.exports.createProxyServer = function (opts) { proxyResponse.on('data', function (chunk) { if (shouldBuffer) { - buffer = Buffer.concat(buffer, chunk); + // buffer = Buffer.concat(buffer, chunk); + buffers.push(chunk); } else { response.write(chunk); } @@ -193,6 +193,8 @@ module.exports.createProxyServer = function (opts) { emitOrRun('interceptResponseContent', function () { writeResponse(newBuffer); }, newBuffer, proxyResponse, isSsl, charset, writeResponse); }; + + buffer = Buffer.concat(buffers, bufferLength); switch (responseEncoding) { case 'gzip': zlib.gunzip(buffer, setupIntercept); @@ -340,7 +342,7 @@ module.exports.createProxyServer = function (opts) { socket.write('HTTP/1.0 200 Connection established\r\n\r\n'); } } catch (error) { - emitter.emit('error', error, 'httpsSocketConnect'); + emitter.emit('error', error, 'httpsSocket'); } }); @@ -355,11 +357,6 @@ module.exports.createProxyServer = function (opts) { } }); - clientSocket.on('error', function (error) { - socket.end(); - emitter.emit('error', error, 'httpsClientSocket'); - }); - clientSocket.on('end', function () { socket.end(); }); socket.on('data', function (data) { @@ -372,12 +369,6 @@ module.exports.createProxyServer = function (opts) { emitter.emit('error', error, 'httpsClientSocketData'); } }); - - socket.on('error', function (error) { - clientSocket.end(); - emitter.emit('error', error, 'httpsSocket'); - }); - socket.on('end', function () { clientSocket.end(); }); }; From fdfb64ff507f406576a9d93bec85fce7b57350a9 Mon Sep 17 00:00:00 2001 From: Craig Condon Date: Sat, 3 Nov 2012 23:23:48 -0500 Subject: [PATCH 3/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3aef50c..8bd6fff 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "homepage": "https://github.com/axiak/filternet", "bugs": "https://github.com/axiak/filternet/issues", "dependencies": { - "bufferjs": "<2.0.0" + "bufferjs": ">1.0.0" }, "main": "index", "license": "BSD", From f4968750cec44000167c472500acd135b8de65bc Mon Sep 17 00:00:00 2001 From: Craig Condon Date: Sat, 17 Nov 2012 23:53:11 -0600 Subject: [PATCH 4/4] fix issue where content wouldn't be returned --- lib/proxy.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/proxy.js b/lib/proxy.js index 965b8d3..736602e 100644 --- a/lib/proxy.js +++ b/lib/proxy.js @@ -135,10 +135,11 @@ module.exports.createProxyServer = function (opts) { var isHtml = (proxyResponse.headers['content-type'] && proxyResponse.headers['content-type'].toLowerCase().indexOf("html") != -1); + var writeResponse = function (shouldBuffer) { var buffer = undefined, buffers = [], bufferLength = 0; if (shouldBuffer) { - bufferLength = ~~(proxyResponse.headers['content-length'] || 0); + bufferLength = 0;//~~(proxyResponse.headers['content-length'] || 0); delete proxyResponse.headers['content-length']; buffer = new Buffer(0); } @@ -149,6 +150,7 @@ module.exports.createProxyServer = function (opts) { }); proxyResponse.on('data', function (chunk) { + bufferLength += chunk.length; if (shouldBuffer) { // buffer = Buffer.concat(buffer, chunk); buffers.push(chunk);