Socket
Socket
Sign inDemoInstall

proxy

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxy

An HTTP proxy written with Node.js (think Squid)


Version published
Weekly downloads
60K
increased by10.81%
Maintainers
0
Weekly downloads
 
Created
Source

proxy

An HTTP proxy written with Node.js (think Squid)

This module provides standard "HTTP proxy" logic. You can script your own server using the proxy server API. Be sure to take a look at the "Examples" section below.

There is also a companion proxy(1) CLI tool, which spawns an HTTP(s) proxy server with the specified options.

You could think of proxy(1) as similar to some of the other popular open source HTTP proxy software:

  • Squid
  • Privoxy
  • Apache with mod_proxy
  • More…

Examples

Basic HTTP(s) proxy server

A basic HTTP(s) server with all the default options. All requests are allowed. CONNECT HTTP method works as well.

import * as http from 'http';
import { createProxy } from 'proxy';

const server = createProxy(http.createServer());
server.listen(3128, () => {
  var port = server.address().port;
  console.log('HTTP(s) proxy server listening on port %d', port);
});

CLI Tool Examples

The proxy(1) CLI tool can be used to spawn HTTP(s) proxy server instances with various options.

Port to bind to

Pass the -p/--port option to with a port number to specify a TCP port to bind to. Defaults to 3128 if none is specified.

$ proxy --port 8080
Custom Proxy-Authenticate command

Pass the -a/--authenticate switch with a command to execute when the client Proxy-Authorization header is given. This command determines whether or not the request is authorized based on the "exit code" of the command.

The relevant request authentication information is passed in as PROXY_AUTH_USERNAME, PROXY_AUTH_PASSWORD and PROXY_AUTH_SCHEME environment variables.

For example, to authorize "Basic" authentication with username "foo" and password "bar":

$ proxy --authenticate 'if \
    [ "$PROXY_AUTH_USERNAME" = "foo" ] && \
    [ "$PROXY_AUTH_PASSWORD" = "bar" ]; \
      then exit 0; \
    fi; \
    exit 1;'
Custom outgoing interface

Pass the -l/--local-address argument with an IP address of the network interface to send the outgoing requests through. It is the equivalent of setting a localAddress field in the options when calling http.request().

$ proxy --local-address 192.168.0.10

Keywords

FAQs

Package last updated on 28 Jun 2024

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

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