Construct HTTP/HTTPS Tunneling Agents

2.0.1 · abandoned · verified Wed Apr 22

caw is a JavaScript utility designed to simplify the creation of HTTP/HTTPS agents for tunneling through proxies. It abstracts the configuration of proxy agents by internally utilizing `tunnel-agent` for the tunneling logic and `get-proxy` for automatic discovery of proxy settings from environment variables if a proxy URL is not explicitly provided. The current stable version is 2.0.1. Due to the age of its underlying dependencies (`tunnel-agent` and `get-proxy`), which are themselves largely unmaintained or deprecated, `caw` has seen no recent development and can be considered abandoned. It serves a niche for older Node.js environments (targeting `node >=4`) that require simple proxy agent construction, but modern applications should seek more actively maintained alternatives.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to create and use `caw` agents with the `got` HTTP client, both with explicit proxy URLs and automatic proxy discovery from environment variables.

const caw = require('caw');
const got = require('got');

// Example using an explicit proxy URL
const proxyAgent = caw('http://your-proxy-server:8080', { protocol: 'http' });

// If no proxy URL is provided, caw will try to get it from environment variables (HTTP_PROXY, HTTPS_PROXY)
const autoProxyAgent = caw();

(async () => {
  try {
    // Make a request using the proxy agent
    const { body: explicitProxyBody } = await got('https://api.github.com/zen', {
      agent: { https: proxyAgent } // Specify https agent for https requests
    });
    console.log('Response with explicit proxy:', explicitProxyBody);

    // Make another request, letting caw discover proxy from env vars
    // For this to work, ensure HTTP_PROXY or HTTPS_PROXY are set in your environment
    // For demonstration, we'll just show the call.
    // process.env.HTTPS_PROXY = 'http://another-proxy.example.com:8081'; // Uncomment to test env var discovery
    const { body: autoProxyBody } = await got('https://ipinfo.io/json', {
      agent: { https: autoProxyAgent }
    });
    console.log('Response with auto-discovered proxy:', autoProxyBody);

  } catch (error) {
    console.error('Request failed:', error.message);
  }
})();

view raw JSON →