Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@mutagen-d/node-proxy-server

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mutagen-d/node-proxy-server

Http and socks proxy server

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
61
41.86%
Maintainers
1
Weekly downloads
 
Created
Source

node-proxy-server

Http and socks proxy server

This module provides http and socks proxy server implementation that can run both protocols in one server instance.

Installation

npm install @mutagen-d/node-proxy-server

Example

const net = require('net')
const { createHttpProxy, createSocksProxy } = require('@mutagen-d/node-proxy-server')

const server = net.createServer()

const options = {
  keepAlive: true,
  keepAliveMsecs: 5000,
}
createHttpProxy(server, options)
createSocksProxy(server, options)

server.listen(8080)

API

createHttpProxy([serverOrOptions [, options]])

  • serverOrOptions - net.Server or HttpProxyServerOptions
  • options - HttpProxyServerOptions

HttpProxyServerOptions:

nametyperequireddefaultdescription
keepAlivebooleannotruecontrols keep-alive behavior
keepAliveMsecsnumberno1000inactivity timeout before close connection
authType"Basic" | "Bearer"no-if defined then proxy authentication required
authRealmstringno-
onAuthOnAuthno-
useHttpRequestbooleanno-if ture then use http.request for HTTP requests, otherwise directly use net.Socket
rewriteOptionsRewriteOptionsno-if defined then rewrite connection options for each subsequence connections
  • Authorization:
const server = createHttpProxy({
  authType: 'Basic',
  onAuth: (auth, callback) => {
    switch (auth.type) {
      case 'Basic':
        // authorize connection
        callback(auth.username === 'test' && auth.password === '1234')
        break
      default:
        // reject connection
        callback(false)
        break
    }
  },
})
  • Rewrite options:
const server = createHttpProxy({
  rewriteOptions: (req, callback) => {
    if (req.url === 'localhost:443') {
      callback({ rejectUnauthorized: false })
    }
  },
})

createSocksProxy([serverOrOptions [, options]])

  • serverOrOptions - net.Server or SocksProxyServerOptions
  • options - SocksProxyServerOptions

SocksProxyServerOptions:

nametyperequireddefaultdescription
keepAlivebooleannotruecontrols keep-alive behavior
keepAliveMsecsnumberno1000inactivity timeout before close connection
onAuthOnAuthno-if defined then prefer password authentication
rewriteOptionsRewriteOptionsno-if defined then rewrite connection options for each subsequence connections
  • Authorization
const server = createSocksProxy({
  onAuth: (username, password, callback) => {
    callback(username === 'test' && password === '1234')
  },
})
  • Rewrite options:
const server = createSocksProxy({
  rewriteOptions: (_, callback) => {
    callback({ rejectUnauthorized: false })
  },
})

Keywords

http

FAQs

Package last updated on 24 Jul 2022

Did you know?

Socket

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