{"id":16311,"library":"caw","title":"Construct HTTP/HTTPS Tunneling Agents","description":"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.","status":"abandoned","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/kevva/caw","tags":["javascript","http","https","proxy","tunnel"],"install":[{"cmd":"npm install caw","lang":"bash","label":"npm"},{"cmd":"yarn add caw","lang":"bash","label":"yarn"},{"cmd":"pnpm add caw","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the core tunneling logic for HTTP/HTTPS agents, but is itself deprecated and unmaintained.","package":"tunnel-agent"},{"reason":"Used to automatically discover proxy settings from environment variables if not specified, also largely unmaintained.","package":"get-proxy"}],"imports":[{"note":"caw is a CommonJS module and does not natively support ES module `import` syntax. For ESM projects, direct migration to an ESM-compatible alternative is recommended.","wrong":"import caw from 'caw';","symbol":"caw","correct":"const caw = require('caw');"},{"note":"The `caw` function is called directly to create an agent instance, it's not a class constructor.","wrong":"agent: new caw()","symbol":"caw (for `agent` option)","correct":"agent: caw('http://proxy.example.com:8080')"}],"quickstart":{"code":"const caw = require('caw');\nconst got = require('got');\n\n// Example using an explicit proxy URL\nconst proxyAgent = caw('http://your-proxy-server:8080', { protocol: 'http' });\n\n// If no proxy URL is provided, caw will try to get it from environment variables (HTTP_PROXY, HTTPS_PROXY)\nconst autoProxyAgent = caw();\n\n(async () => {\n  try {\n    // Make a request using the proxy agent\n    const { body: explicitProxyBody } = await got('https://api.github.com/zen', {\n      agent: { https: proxyAgent } // Specify https agent for https requests\n    });\n    console.log('Response with explicit proxy:', explicitProxyBody);\n\n    // Make another request, letting caw discover proxy from env vars\n    // For this to work, ensure HTTP_PROXY or HTTPS_PROXY are set in your environment\n    // For demonstration, we'll just show the call.\n    // process.env.HTTPS_PROXY = 'http://another-proxy.example.com:8081'; // Uncomment to test env var discovery\n    const { body: autoProxyBody } = await got('https://ipinfo.io/json', {\n      agent: { https: autoProxyAgent }\n    });\n    console.log('Response with auto-discovered proxy:', autoProxyBody);\n\n  } catch (error) {\n    console.error('Request failed:', error.message);\n  }\n})();","lang":"javascript","description":"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."},"warnings":[{"fix":"Consider migrating to actively maintained libraries such as `http-proxy-agent`, `https-proxy-agent`, or `socks-proxy-agent` for proxy tunneling, ideally used with modern HTTP clients like `undici` or `axios` with appropriate proxy agent integration.","message":"caw relies on deprecated and unmaintained underlying dependencies (`tunnel-agent` and `get-proxy`). This can lead to security vulnerabilities, lack of compatibility with modern Node.js versions, and unaddressed bugs.","severity":"breaking","affected_versions":">=1.0"},{"fix":"Always use `const caw = require('caw');` for importing. For ESM-only projects, a direct migration to an ESM-first proxy agent library is the most robust solution.","message":"caw is a CommonJS module and does not provide native ES Module (ESM) support. Using `import` syntax will typically result in errors in pure ESM environments without a transpilation step.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Thoroughly test `caw` on your target Node.js version. For production environments, it is highly recommended to migrate to a current, actively maintained solution that explicitly supports your Node.js runtime.","message":"While `caw` states compatibility with Node.js versions `>=4`, its internal mechanisms and dependencies may not function correctly or securely on modern Node.js versions (e.g., Node.js 14+).","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Always provide an explicit `proxy` URL to `caw(proxyUrl)` for predictable behavior. If relying on environment variables, ensure they are correctly configured and understood for the application's context. Always be mindful of `NO_PROXY` to prevent local requests from being proxied.","message":"When no proxy URL is explicitly provided to `caw()`, it attempts to automatically discover proxy settings from environment variables (`HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY`). This can lead to unintended proxying if these variables are set in your environment without your explicit knowledge or intent for a specific application.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change the import statement to `const caw = require('caw');` or convert your project to CommonJS. For pure ESM projects, migrate to an ESM-compatible proxy agent library.","cause":"Attempting to import `caw` using ES module `import` syntax in an ES module environment.","error":"ReferenceError: require is not defined"},{"fix":"Verify the proxy URL, port, and authentication credentials. Ensure network connectivity from your application to the proxy server. Check the proxy server's logs for more detailed error information. Also, check for `NO_PROXY` environment variables that might unintentionally prevent proxying for certain domains.","cause":"The configured proxy server either rejected the connection, is misconfigured, or network issues prevented the application from reaching the proxy.","error":"Error: tunneling socket could not be established, cause=..."},{"fix":"Upgrade to a modern, actively maintained HTTP/HTTPS proxy agent library (e.g., `@http-proxy-agent/https`, `@https-proxy-agent/https`) that is explicitly compatible with your Node.js version and chosen HTTP client.","cause":"This or similar `TypeError` issues often arise when the `caw` agent, built on older `tunnel-agent` mechanisms, becomes incompatible with newer Node.js `http`/`https` module internals or other HTTP client libraries due to its age.","error":"TypeError: Cannot read properties of undefined (reading 'protocol')"}],"ecosystem":"npm"}