{"id":17243,"library":"hagent","title":"hagent: HTTP Agent for Whistle","description":"hagent is a foundational Node.js module designed to provide HTTP and HTTPS agent functionality specifically tailored for use with Whistle, a cross-platform network debugging and proxy tool. It enables Whistle to manage and proxy network requests at a lower level, handling connection pooling and socket management. Currently at version `0.9.3`, the package has not seen active development since 2020, with its last commit dating back approximately four years. This indicates an abandoned status, meaning it is no longer maintained and may not be compatible with newer Node.js versions or contain unpatched vulnerabilities. Its core functionality revolves around extending Node.js's native `http.Agent` to integrate with Whistle's proxying mechanisms, offering control over persistent connections.","status":"abandoned","version":"0.9.3","language":"javascript","source_language":"en","source_url":"https://github.com/avwo/hagent","tags":["javascript","whistle","http-agent"],"install":[{"cmd":"npm install hagent","lang":"bash","label":"npm"},{"cmd":"yarn add hagent","lang":"bash","label":"yarn"},{"cmd":"pnpm add hagent","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. There is no ESM support in v0.9.3.","wrong":"import { HttpClientAgent } from 'hagent'; // hagent@0.9.3 is CommonJS-only\nconst HttpClientAgent = require('hagent').HttpClientAgent; // Not strictly wrong, but destructuring is cleaner","symbol":"HttpClientAgent","correct":"const { HttpClientAgent } = require('hagent');"},{"note":"Used for HTTPS connections; similar CommonJS-only import as HttpClientAgent.","wrong":"import { HttpsClientAgent } from 'hagent'; // hagent@0.9.3 is CommonJS-only","symbol":"HttpsClientAgent","correct":"const { HttpsClientAgent } = require('hagent');"},{"note":"The package exports an object containing both HttpClientAgent and HttpsClientAgent as named properties, not a default export in the traditional sense. Direct destructuring is often preferred.","symbol":"hagent (default export)","correct":"const hagent = require('hagent');\n// Then access hagent.HttpClientAgent or hagent.HttpsClientAgent"}],"quickstart":{"code":"const http = require('http');\nconst { HttpClientAgent } = require('hagent');\n\n// Configure a basic HTTP agent for use with Whistle\nconst agent = new HttpClientAgent({\n  // These options are standard for Node.js http.Agent\n  keepAlive: true,\n  maxSockets: 10,\n  maxFreeSockets: 5,\n  // The 'whistle' option is specific to how hagent integrates\n  // It typically holds configurations like the Whistle server address\n  // For demonstration, we'll use a placeholder whistle server address\n  whistle: {\n    host: '127.0.0.1',\n    port: 8899, // Default Whistle proxy port\n  },\n});\n\nconst options = {\n  hostname: 'example.com',\n  port: 80,\n  path: '/',\n  method: 'GET',\n  agent: agent, // Use the hagent instance\n};\n\nconst req = http.request(options, (res) => {\n  console.log(`STATUS: ${res.statusCode}`);\n  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);\n  res.setEncoding('utf8');\n  let rawData = '';\n  res.on('data', (chunk) => { rawData += chunk; });\n  res.on('end', () => {\n    try {\n      console.log('Response Body Snippet:', rawData.substring(0, 200) + '...');\n    } catch (e) {\n      console.error(e.message);\n    }\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(`problem with request: ${e.message}`);\n});\n\n// Write data to request body\nreq.end();","lang":"javascript","description":"This quickstart demonstrates how to instantiate and use `HttpClientAgent` to make an HTTP request. The agent is configured to connect through a hypothetical Whistle proxy, showing how it would be integrated into a Node.js HTTP client call."},"warnings":[{"fix":"Consider migrating to actively maintained HTTP agent solutions or newer versions of Whistle that might embed similar functionality or provide alternative integration points. If Whistle itself is still in use, check its documentation for recommended agent configurations.","message":"The `hagent` package has been abandoned since April 2020. It is unlikely to be compatible with modern Node.js versions (e.g., Node.js 16+), potentially leading to runtime errors, unexpected behavior, or security vulnerabilities.","severity":"breaking","affected_versions":">=0.9.3"},{"fix":"Always use `const { HttpClientAgent } = require('hagent');` or `const hagent = require('hagent');` for module imports.","message":"This package is strictly CommonJS (`require`) and does not provide ES Module (`import`) support. Attempting to use `import { HttpClientAgent } from 'hagent'` will result in a module resolution error.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Perform a thorough security audit before considering use, or ideally, replace with a maintained alternative. Rely on Whistle's own mechanisms if they provide a maintained HTTP agent solution.","message":"Due to its abandoned status, `hagent` likely contains unpatched security vulnerabilities or bugs. Using it in production environments is highly discouraged as it poses a significant security risk.","severity":"gotcha","affected_versions":">=0.9.3"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using `require()` for this CommonJS-only package: `const { HttpClientAgent } = require('hagent');`","cause":"Attempting to use `require()` on a package that is ESM-only, or more likely in this context, attempting to use `import` with a CommonJS-only package like `hagent`.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported."},{"fix":"Verify that `hagent` is correctly installed (`npm install hagent`) and that `HttpClientAgent` or `HttpsClientAgent` are correctly imported and instantiated before being passed to Node.js's native `http.request` or `https.request` methods.","cause":"This error typically indicates that the `agent` object passed to `http.request` or `https.request` is not a valid agent instance, or that the `http` module itself is not correctly imported.","error":"TypeError: Cannot read property 'request' of undefined (or similar for http/https methods)"}],"ecosystem":"npm","meta_description":null}