Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var http = require('http')
, zlib = require('zlib')
, sniparse = require('./sniparse');

require('bufferjs/concat');
require('bufferjs/add-chunk');
require('./regexp-escape');

Expand Down Expand Up @@ -136,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, bufferLength = 0;
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);
}
Expand All @@ -150,8 +150,10 @@ module.exports.createProxyServer = function (opts) {
});

proxyResponse.on('data', function (chunk) {
bufferLength += chunk.length;
if (shouldBuffer) {
buffer = Buffer.concat(buffer, chunk);
// buffer = Buffer.concat(buffer, chunk);
buffers.push(chunk);
} else {
response.write(chunk);
}
Expand Down Expand Up @@ -193,6 +195,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);
Expand Down Expand Up @@ -340,7 +344,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');
}
});

Expand All @@ -355,11 +359,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) {
Expand All @@ -372,12 +371,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(); });
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"homepage": "https://github.com/axiak/filternet",
"bugs": "https://github.com/axiak/filternet/issues",
"dependencies": {
"bufferjs": ">= 1.0.0"
"bufferjs": ">1.0.0"
},
"main": "index",
"license": "BSD",
Expand Down