hagent: HTTP Agent for Whistle

0.9.3 · abandoned · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

const http = require('http');
const { HttpClientAgent } = require('hagent');

// Configure a basic HTTP agent for use with Whistle
const agent = new HttpClientAgent({
  // These options are standard for Node.js http.Agent
  keepAlive: true,
  maxSockets: 10,
  maxFreeSockets: 5,
  // The 'whistle' option is specific to how hagent integrates
  // It typically holds configurations like the Whistle server address
  // For demonstration, we'll use a placeholder whistle server address
  whistle: {
    host: '127.0.0.1',
    port: 8899, // Default Whistle proxy port
  },
});

const options = {
  hostname: 'example.com',
  port: 80,
  path: '/',
  method: 'GET',
  agent: agent, // Use the hagent instance
};

const req = http.request(options, (res) => {
  console.log(`STATUS: ${res.statusCode}`);
  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
  res.setEncoding('utf8');
  let rawData = '';
  res.on('data', (chunk) => { rawData += chunk; });
  res.on('end', () => {
    try {
      console.log('Response Body Snippet:', rawData.substring(0, 200) + '...');
    } catch (e) {
      console.error(e.message);
    }
  });
});

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

// Write data to request body
req.end();

view raw JSON →