HTTP Proxy Tunneling Agent

0.6.0 · abandoned · verified Wed Apr 22

tunnel-agent is an HTTP proxy tunneling agent originally extracted from the now-deprecated `mikeal/request` library. Its primary function is to facilitate HTTP and HTTPS requests through a proxy server, enabling applications to bypass network restrictions or access resources securely via a tunnel. The package's latest version, 0.6.0, was published over nine years ago, in March 2017. It is considered unmaintained and effectively abandoned, with no new versions or significant activity in recent years. Developers should exercise extreme caution or avoid using this package due to its unmaintained status and potential security vulnerabilities, especially given the historical context of its origin from a library with known security issues. Modern alternatives offer better security, maintenance, and features for proxy tunneling. There is an active `@postman/tunnel-agent` fork, but it has its own separate security concerns including detected malware in some versions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure and use `tunnel-agent` to make an HTTP request through an HTTP proxy. It uses environment variables for proxy configuration for security.

const http = require('http');
const tunnel = require('tunnel-agent');

// Configure the tunneling agent to go through an HTTP proxy
const tunnelingAgent = tunnel.httpOverHttp({
  proxy: {
    host: process.env.HTTP_PROXY_HOST ?? '127.0.0.1',
    port: parseInt(process.env.HTTP_PROXY_PORT ?? '8080', 10),
    proxyAuth: process.env.HTTP_PROXY_AUTH ?? '' // Optional: 'user:password'
  }
});

// Options for the actual HTTP request
const requestOptions = {
  host: 'example.com',
  port: 80,
  path: '/',
  agent: tunnelingAgent,
  headers: {
    'User-Agent': 'tunnel-agent-example'
  }
};

// Make the request using the tunneling agent
const req = http.request(requestOptions, (res) => {
  console.log(`STATUS: ${res.statusCode}`);
  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
  res.setEncoding('utf8');
  let data = '';
  res.on('data', (chunk) => { data += chunk; });
  res.on('end', () => {
    console.log('No more data in response.');
    // console.log(data); // Uncomment to see response body
  });
});

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

req.end();

view raw JSON →