Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

proxy-chain

Package Overview
Dependencies
Maintainers
9
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxy-chain - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0-beta.0

dist/custom_connect.d.ts

4

dist/server.d.ts

@@ -29,3 +29,4 @@ /// <reference types="node" />

isHttp: boolean;
customResponseFunction: CustomResponseOpts['customResponseFunction'] | null;
customResponseFunction?: CustomResponseOpts['customResponseFunction'] | null;
customConnectServer?: http.Server | null;
localAddress?: string;

@@ -46,2 +47,3 @@ ipFamily?: number;

customResponseFunction?: CustomResponseOpts['customResponseFunction'];
customConnectServer?: http.Server | null;
requestAuthentication?: boolean;

@@ -48,0 +50,0 @@ failMsg?: string;

@@ -21,2 +21,3 @@ "use strict";

const statuses_1 = require("./statuses");
const custom_connect_1 = require("./custom_connect");
// TODO:

@@ -234,2 +235,6 @@ // - Implement this requirement from rfc7230

const data = { request, sourceSocket: socket, head, handlerOpts: handlerOpts, server: this, isPlain: false };
if (handlerOpts.customConnectServer) {
socket.unshift(head); // See chain.ts for why we do this
return await (0, custom_connect_1.customConnect)(socket, handlerOpts.customConnectServer);
}
if (handlerOpts.upstreamProxyUrlParsed) {

@@ -261,2 +266,3 @@ this.log(socket.proxyChainId, `Using HandlerTunnelChain => ${request.url}`);

customResponseFunction: null,
customConnectServer: null,
};

@@ -350,2 +356,3 @@ this.log(request.socket.proxyChainId, `!!! Handling ${request.method} ${request.url} HTTP/${request.httpVersion}`);

handlerOpts.dnsLookup = funcResult.dnsLookup;
handlerOpts.customConnectServer = funcResult.customConnectServer;
// If not authenticated, request client to authenticate

@@ -352,0 +359,0 @@ if (funcResult.requestAuthentication) {

{
"name": "proxy-chain",
"version": "2.1.1",
"version": "2.2.0-beta.0",
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",

@@ -50,3 +50,3 @@ "main": "dist/index.js",

"@types/jest": "^28.1.2",
"@types/node": "^18.0.0",
"@types/node": "^18.8.3",
"@typescript-eslint/eslint-plugin": "5.29.0",

@@ -53,0 +53,0 @@ "@typescript-eslint/parser": "5.29.0",

@@ -247,2 +247,57 @@ # Programmable HTTP proxy server for Node.js

## Routing CONNECT to another HTTP server
While `customResponseFunction` enables custom handling methods such as `GET` and `POST`, many HTTP clients rely on `CONNECT` tunnels.
It's possible to route those requests differently using the `customConnectServer` option. It accepts an instance of Node.js HTTP server.
```javascript
const http = require('http');
const ProxyChain = require('proxy-chain');
const exampleServer = http.createServer((request, response) => {
response.end('Hello from a custom server!');
});
const server = new ProxyChain.Server({
port: 8000,
prepareRequestFunction: ({ request, username, password, hostname, port, isHttp }) => {
if (request.url.toLowerCase() === 'example.com:80') {
return {
customConnectServer: exampleServer,
};
}
return {};
},
});
server.listen(() => {
console.log(`Proxy server is listening on port ${server.port}`);
});
```
In the example above, all CONNECT tunnels to `example.com` are overridden.
This is an unsecure server, so it accepts only `http:` requests.
In order to intercept `https:` requests, `https.createServer` should be used instead, along with a self signed certificate.
```javascript
const https = require('https');
const fs = require('fs');
const key = fs.readFileSync('./test/ssl.key');
const cert = fs.readFileSync('./test/ssl.crt');
const exampleServer = https.createServer({
key,
cert,
}, (request, response) => {
response.end('Hello from a custom server!');
});
```
```diff
-if (request.url.toLowerCase() === 'example.com:80') {
+if (request.url.toLowerCase() === 'example.com:443') {
```
## Closing the server

@@ -249,0 +304,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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