Skip to content

JS Proxy library with support for request/response interception, optional SSL MITM, external proxy

License

Notifications You must be signed in to change notification settings

sannysoft/newproxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Apr 24, 2024
817256c · Apr 24, 2024

History

58 Commits
Sep 20, 2021
Apr 24, 2024
Oct 27, 2021
May 22, 2020
Apr 24, 2024
Oct 27, 2021
May 22, 2020
May 22, 2020
May 22, 2020
May 22, 2020
Apr 24, 2024
May 22, 2020
Oct 28, 2021
Apr 24, 2024
Apr 24, 2024
Oct 27, 2021
Apr 24, 2024
Apr 24, 2024

Repository files navigation

NewProxy

npm npm type definitions npm

JS Proxy library with support for request/response rewriting, optional SSL MITM (man-in-the-middle), external proxy.

Adding as dependency

npm i newproxy

Usage

import { NewProxyBuilder }  from 'newproxy';

const proxy = NewProxyBuilder.new()
  .sslMitm((req, clientSocket, head) => true)
  .requestInterceptor(async (rOptions, clientReq, clientRes, ssl) => {
    clientReq.setTimeout(10000); // Set request timeout to 10 seconds

    console.log(`URL requested:${rOptions.protocol}//${rOptions.hostname}:${rOptions.port}`);
    console.log('Cookie:', rOptions.headers.cookie);

    if (rOptions.url.includes('test')) {
      clientRes.setHeader('Content-Type', 'application/json');
      clientRes.end('Hello NewProxy!');
      // If we call clientRes.end and close client socket in request interception
      // then no other actions are performed
    }
  })
  .responseInterceptor(async (clientReq, clientRes, proxyReq, proxyRes, ssl) => {
    // proxyRes will be piped to clientRes, we can change proxyRes or write to clientRes directly here
    proxyRes.headers['test_header'] = 'test';

    if (proxyRes.statusCode === 301) {
      clientRes.setHeader('Content-Type', 'text/html');
      clientRes.statusCode = 404;
      clientRes.end('NO REDIRECTS HERE');
    }
  })
  .externalProxyNoMitm('http://127.0.0.1:8800') // Set external proxy for non-MITM SSL requests
  .externalProxy('http://127.0.0.1:8888')
  .build(); // We can set external proxy statically or by fn
  
// Start listening 
(async () => {
  await proxy.run();
})();

...

await proxy.stop();

Features

  • Optional request/response interception
  • Optional MITM for SSL requests
  • Optional external proxy
  • Written in TypeScript

Examples

Multiple example files are available in /examples folder

About

JS Proxy library with support for request/response interception, optional SSL MITM, external proxy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published