Socket
Socket
Sign inDemoInstall

tcproxy

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcproxy - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

25

lib/proxy.js

@@ -27,2 +27,9 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */

/**
* @ 代理错误处理函数
*/
this._whenProxyError = function (error, client) {
client.end();
};
/**
* @ 协议解析函数

@@ -58,8 +65,14 @@ */

var onerror = function (err) {
_that._whenProxyError(err, client);
};
var socket = net.createConnection(R, function () {
socket.write(H);
client.pipe(socket);
socket.pipe(client);
this.removeListener('error', onerror);
this.write(H);
client.pipe(this);
this.pipe(client);
client.resume();
});
socket.once('error', onerror);
}

@@ -76,2 +89,8 @@ });

ProxyServer.prototype.whenProxyError = function (handle) {
if ('function' === (typeof handle)) {
this._whenProxyError = handle;
}
};
ProxyServer.prototype.listen = function () {

@@ -78,0 +97,0 @@ this.server.listen.apply(this.server, arguments);

2

package.json

@@ -5,3 +5,3 @@ {

"keywords": [ "tcp proxy" ],
"version": "0.0.1",
"version": "0.0.2",
"author": "Aleafs Zhang (zhangxc83@gmail.com)",

@@ -8,0 +8,0 @@ "repository": {

@@ -70,3 +70,7 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */

var proxy = sproxy.createServer();
proxy.use(function (buffer) {
proxy.whenProxyError(function (error, client) {
client.end(error.stack);
});
proxy.use(function (buffer, socket) {
buffer = buffer.toString();

@@ -85,2 +89,6 @@ if (buffer.indexOf('hello') > -1) {

}
return {
'path' : 'i/am/not/exists',
};
});

@@ -91,3 +99,3 @@

var count = 2;
var count = 3;
var close = function () {

@@ -118,2 +126,10 @@ if (0 === (--count)) {

});
var c3 = net.createConnection(_FD, function () {
this.write('test error');
this.on('data', function (data) {
data.toString().should.include('Error: connect ENOENT');
close();
});
});
});

@@ -120,0 +136,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