/** * HTTP Agent Factory Utilities * * This module provides factory functions for creating HTTP/HTTPS agents * with consistent configuration to reduce duplicated agent setup code. * * Why agent factories matter: * - Connection pooling: Reuses connections for better performance * - Resource management: Prevents socket exhaustion and memory leaks * - Consistency: Ensures all HTTP requests use the same configuration * - Tuning: Allows optimization for different workload patterns * * Performance considerations: * - Keep-alive connections reduce TCP handshake overhead * - Socket limits prevent resource exhaustion under load * - Timeouts ensure failed connections don't hang indefinitely * - Free socket caching enables rapid connection reuse */ import https from 'https'; import http from 'http'; /** * Agent configuration extending the standard Node.js AgentOptions. * keepAliveTimeout is a project-level field (passed through to Agent options * and used as a configuration marker); Node's socket-level idle timeout is * controlled via the Agent's keepAliveMsecs option which is inherited here * through https.AgentOptions. */ export type AgentConfig = https.AgentOptions & { keepAliveTimeout?: number; }; /** * Create HTTPS agent with specified configuration. * * HTTPS agents handle encrypted connections and require special configuration * for TLS/SSL handling, certificate validation, and secure connection management. * * @param options - Agent configuration options (merged with defaults) * @returns Configured HTTPS agent */ export declare function createHTTPSAgent(options?: AgentConfig): https.Agent; /** * Create HTTP agent with specified configuration. * * HTTP agents handle unencrypted connections and are typically faster than * HTTPS agents due to the lack of encryption overhead. Suitable for internal * services, development environments, and non-sensitive data transmission. * * @param options - Agent configuration options (merged with defaults) * @returns Configured HTTP agent */ export declare function createHTTPAgent(options?: AgentConfig): http.Agent; /** * Create agent based on protocol ('http' or 'https'). * * Abstracts protocol-specific agent creation, allowing callers to specify * the protocol as a string. Provides validation and error handling for * unsupported protocols. * * @param protocol - Protocol string ('http' or 'https') * @param options - Agent configuration options * @returns Configured agent for the specified protocol * @throws {Error} When the protocol is not 'http' or 'https' */ export declare function createAgent(protocol: string, options?: AgentConfig): http.Agent | https.Agent; /** * Create high-performance agent configuration for heavy workloads. * * Optimized for applications that handle high volumes of HTTP requests such * as API gateways, microservices, and web scrapers. Maximises connection * reuse and throughput at the cost of higher memory usage. * * @param options - Additional configuration options (merged on top) * @returns High-performance agent configuration object */ export declare function createHighPerformanceConfig(options?: AgentConfig): AgentConfig; /** * Create low-resource agent configuration for lightweight applications. * * Optimized for applications with limited memory and CPU resources such as * serverless functions, IoT devices, and embedded systems. Minimises resource * usage while maintaining reasonable performance for light workloads. * * @param options - Additional configuration options (merged on top) * @returns Low-resource agent configuration object */ export declare function createLowResourceConfig(options?: AgentConfig): AgentConfig; //# sourceMappingURL=agentFactory.d.ts.map