Socket
Socket
Sign inDemoInstall

tcp-proxy.js

Package Overview
Dependencies
12
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tcp-proxy.js

simple tcp proxy


Version published
Weekly downloads
21K
increased by0.87%
Maintainers
1
Install size
234 kB
Created
Weekly downloads
 

Readme

Source

tcp-proxy.js

a simple tcp proxy

NPM version Build Status Appveyor status Coverage Status

Usage

$ npm i tcp-proxy.js --save

create proxy

const TCPProxy = require('tcp-proxy.js');
const proxy = new TCPProxy({ port: 9229 });
proxy.createProxy({
  forwardPort: 9999,
  forwardHost: 'localhost',
});

end proxy

proxy.end();

interceptor

proxy.createProxy({
  forwardPort: 9999,
  interceptor: {
    client(chunk) {
      // request => proxy server => interceptor.client => forward server
      const data = chunk.toString();
      const newData = data.replace('GET / ', 'GET /tom ');
      return Buffer.from(newData);
    },
    server(chunk) {
      // forward server => interceptor.server => proxy server => response
      const data = chunk.toString();
      const newData = data.replace('hello tom', 'bello tom');
      return Buffer.from(newData);
    },
  },
});

async interceptor

proxy.createProxy({
  forwardPort: 9999,
  interceptor: {
    client(chunk) {
      // request => proxy server => interceptor.client => forward server
      const data = chunk.toString();
      return new Promise(resolve => {
        setTimeout(() => {
          const newData = data.replace('GET / ', 'GET /tom ');
          resolve(Buffer.from(newData));
        }, 200);
      });
    },
  },
});

Keywords

FAQs

Last updated on 21 Sep 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc