Node HTTP/HTTPS Forward Proxy Agent

2.4.0 · abandoned · verified Wed Apr 22

proxying-agent is a Node.js library providing an HTTP/HTTPS forward proxy agent. It is built upon Node's native `http.Agent` and offers features for transparently routing HTTP and HTTPS requests through a specified proxy server. Key capabilities include support for SSL tunneling via the HTTP CONNECT method, Basic authentication, and a beta implementation of NTLM authentication, allowing for domain-specific username formats (e.g., `domain\username`). The library also provides a `globalize` method to easily configure all subsequent `http` and `https` requests to use a designated proxy. The current stable version is 2.4.0, released in July 2017. Due to its age, it is considered abandoned, with no active development or maintenance since its last update. This lack of recent activity suggests potential incompatibilities with newer Node.js versions and a risk of unaddressed security vulnerabilities, making it crucial for users to assess its suitability for modern applications.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to create and use `proxying-agent` with NTLM authentication for an HTTPS request, including the crucial `req.on('socket')` pattern for NTLM.

const http = require('http');
const https = require('https');

const proxyOptions = {
  proxy: 'http://username:password@proxy.example.com:8080',
  authType: 'ntlm',
  ntlm: {
    domain: 'MYDOMAIN',
    workstation: process.env.WORKSTATION_NAME ?? 'my-machine' // Optional, for NTLM
  }
};

const proxyingAgent = require('proxying-agent').create(proxyOptions, 'https://target.example.com');

const req = https.request({
  host: 'target.example.com',
  port: 443,
  method: 'GET',
  path: '/',
  agent: proxyingAgent
});

req.on('socket', (socket) => {
  // For NTLM, delay sending request data until the socket is assigned to prevent premature closure.
  // For other auth types, you might send data immediately after req creation.
  console.log('Socket assigned, sending request data...');
  req.end('Hello from client!'); // No data for GET, but demonstrates the pattern
});

req.on('response', (res) => {
  console.log(`STATUS: ${res.statusCode}`);
  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
  res.setEncoding('utf8');
  res.on('data', (chunk) => {
    console.log(`BODY: ${chunk}`);
  });
  res.on('end', () => {
    console.log('No more data in response.');
  });
});

req.on('error', (e) => {
  console.error(`problem with request: ${e.message}`);
});

// If not using NTLM or delaying data, you would call req.end() directly here.
// req.end(); // For non-NTLM or immediate data send

view raw JSON →